السلام عليكم
سؤالي في gui
هو اني لما اسوي فورم فيه مكونات
واحد هذي الكونات زر لما اضغط عليه تنحذف المكونات السابقه و تظهر مكونات اخرى
الكود ما في مشكله بس يوم اضغط على الزر ما تظهر المكونات الجديده الا لما اصغر الفريم واكبره او اني اغير السايز من الكود فما ادري اش المشكله انا ابغى تتغير المكونات بدون ما اغير السايز تبع الفريم
فهل في طريقه ارجو تساعدوني
وهذا كود برنامجي بس ترا فيه صور يعني ماراح يشتغل .. وانا اشتغل على النت بينزز
public class hashasgame extends JFrame
{
Icon pic1 = new ImageIcon( getClass().getResource("cry1.gif"));
Icon pic2 = new ImageIcon( getClass().getResource("cry2.gif"));
Icon pic3 = new ImageIcon( getClass().getResource("cry3.gif"));
Icon pic4 = new ImageIcon( getClass().getResource("lago.jpg"));
Icon pic5 = new ImageIcon( getClass().getResource("meme see.jpg"));
Icon pic6 = new ImageIcon( getClass().getResource("memelap.jpg"));
Icon pic7 = new ImageIcon( getClass().getResource("memewhat.jpg"));
Icon pic8 = new ImageIcon( getClass().getResource("hashas.jpg"));
JLabel l1 = new JLabel( pic1,SwingConstants.CENTER);
JLabel l2 = new JLabel( pic2,SwingConstants.CENTER);
JLabel l3 = new JLabel( pic3,SwingConstants.CENTER);
JLabel l4 = new JLabel( pic4,SwingConstants.CENTER);
JLabel l5 = new JLabel( pic5,SwingConstants.CENTER);
JLabel l6 = new JLabel( pic6,SwingConstants.CENTER);
JLabel l7 = new JLabel( pic7,SwingConstants.CENTER);
JLabel l8 = new JLabel( pic8,SwingConstants.CENTER);
JLabel name = new JLabel("what is your name ?");
JLabel bank = new JLabel("Faces you have");
JButton startplaying = new JButton ("Start Playing ");
JButton story = new JButton ("see the Story of Game");
JButton next = new JButton ("NEXT");
JButton exit = new JButton ("OUT Game ");
JButton menue = new JButton ("MAIN MENUE ");
JButton yes = new JButton ("yes ");
JButton no = new JButton ("no ");
JTextField playername = new JTextField();
JTextField hellouser = new JTextField();
JTextField hellostory = new JTextField();
JTextField q = new JTextField();
Container w =getContentPane();
JPanel top = new JPanel();
JPanel center = new JPanel();
JPanel end = new JPanel();
JPanel back = new JPanel();
Font font = new Font("SansSerif", Font.ITALIC, 20);
int counter =0 , count = 0 , nextcounter = 0;
public hashasgame()
{
setSize(300,300);
setTitle("Wellcome in HASHAS Game ");
setLocationRelativeTo(null);// to put the screen in the midill
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
name.setFont(font);
name.setForeground(Color.BLUE);
playername.setFont(font);
playername.setForeground(Color.PINK);
top.setLayout(new GridLayout(2,0));
top.add(name);
top.add(playername );
end.add(menue);
w.setLayout(new GridLayout(3,0));
w.add(top);
w.add(center);
w.add(end);
hellouser.setEditable(false);
//-------------------------------------
menue.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
w.removeAll(); top.removeAll();
center.removeAll(); end.removeAll();
String username = playername.getText();
hellouser.setText("Hello Dear ,, "+ username+" :");
hellouser.setFont(font);
hellouser.setForeground(Color.orange);
w.removeAll(); top.removeAll(); end.removeAll();
top.setLayout(new FlowLayout());
center.setLayout(new FlowLayout());
end.setLayout(new FlowLayout());
top.add(hellouser);
center.add(startplaying);
end.add(story);
end.add(exit);
w.setLayout(new GridLayout(3,0));
w.add(top);
w.add(center);
w.add(end);
setSize(500 , 400);
setLocationRelativeTo(null);
}
});
exit.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// code to be executed when button is pushed
System.exit(0);
}
});
story.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
w.removeAll(); top.removeAll();
center.removeAll(); end.removeAll();
setExtendedState(Frame.MAXIMIZED_BOTH); // full screen
setLocationRelativeTo(null);
hellouser.setText("بدأت القصه عندما لاحضت ميار انشغال بسمه");
hellostory.setText("عنها بحسحس فشعرت بالوحده الشديده ");
hellostory.setEditable(false);
hellostory.setFont(font);
hellouser.setForeground(Color.black);
top.setLayout(new GridLayout(2,0));
top.add(hellouser);
top.add(hellostory);
end.add(next);
w.setLayout(new GridLayout(3,0));
w.add(top); w.add(l5); w.add(end);
}
});
next.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(nextcounter == 0)
{
w.removeAll();
top.removeAll();
center.removeAll();
end.removeAll();
setLocationRelativeTo(null);
hellouser.setText("بدأت تفكر و تفكر لتجد حل لهذه المصيبه ");
top.add(hellouser);
end.add(next);
w.setLayout(new GridLayout(3,0));
w.add(top); w.add(l7); w.add(end);
nextcounter++;
}
else if(nextcounter == 1)
{
w.removeAll();
top.removeAll();
center.removeAll();
end.removeAll();
setLocationRelativeTo(null);
hellouser.setText("في الاخير قررت ان تستعين بأصدقاها ");
hellostory.setText("لجين واسامه فاتصلت بهم بالجهاز عن بعد للاستشاره ");
top.add(hellouser);
top.add(hellostory);
end.add(next);
center.add(l6); center.add(l4);
w.setLayout(new GridLayout(3,0));
w.add(top); w.add(center); w.add(end);
nextcounter++;
}
else
{
w.removeAll();
top.removeAll();
center.removeAll();
end.removeAll();
setLocationRelativeTo(null);
hellouser.setText("فقرروا قطع الحليب لمده اسبوعين عن حسحس !!");
hellostory.setText("لتخفيف الحكم اجمع خمس من الوجوه الباكيه على الاقل ");
top.add(hellouser);
top.add(hellostory);
end.add(menue);
center.add(l1); center.add(l2);center.add(l3);
w.setLayout(new GridLayout(3,0));
w.add(top); w.add(center); w.add(end);
}
}});
startplaying.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
counter=0; count=0;
w.removeAll(); top.removeAll();
center.removeAll(); end.removeAll();
setSize(900, 700);
setLocationRelativeTo(null);
w.setLayout(new BorderLayout());
q.setText("عدد الصلوات في اليوم 5 صلوات ؟؟");
q.setEditable(false);
q.setFont(font);
q.setForeground(Color.red);
top.add(hellouser);
center.setLayout(new FlowLayout());
center.add(bank);
end.setLayout(new BorderLayout());
end.add(l8 , BorderLayout.NORTH);
end.add(q, BorderLayout.CENTER);
back.add(yes); back.add(no); end.add(back , BorderLayout.SOUTH);
w.add(top , BorderLayout.NORTH);
w.add(end , BorderLayout.WEST);
w.add(center , BorderLayout.EAST);
}
});
yes.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(counter == 0)
{
q.setText("عدد المدن المقدسه في المملكه 3 مدن ");
counter++;
}
else if(counter == 1)
{
q.setText("اول اولاد ادم هو قابيل ");
counter++;
}
else if (counter == 2)
{
q.setText("اول ما خلق الله هو الحبر ");
counter++;
center.add(l3);
count++ ;
}
else if(counter == 3)
{
q.setText("اول من قدم للمدينه هو مصعب بن عمير ");
counter++;
}
else if(counter == 4)
{
q.setText("الحيوان الذي ينام على ظهره هو الثعبان ");
counter++;
center.add(l2);
count++;
}
else if(counter == 5 )
{
q.setText("الغشاء الذي يغطي العين هو القرنيه ");
counter++;
}
else if(counter == 6)
{
q.setText("توجد اطول شجره في العالم في ايطاليا ");
counter++;
center.add(l1);
count ++ ;
}
else if(counter == 7)
{
q.setText("ام قشعم هي انثى النسر ");
counter++ ;
}
else if(counter == 8 )
{
q.setText("الهاتف يسمع ولا يتكلم ");
counter++;
center.add(l3);
count++;
}
else if(counter == 9 )
{
q.setText("لا يوجد في الاسفنج اي ثقوب");
counter++;
}
else if(counter == 10)
{
q.setText("يعيش الجمل لمده 25 عام ");
counter++;
}
else
{
counter++;
center.add(l3);
count++;
}
if(counter >= 11)
{
w.removeAll(); top.removeAll();
center.removeAll(); end.removeAll();
setLocationRelativeTo(null);
top.setLayout(new GridLayout(1,2));
top.add(l2) ; top.add(l1);
if(count >=5)
q.setText("حسحس يقول لك شكرا لانك جمعت خمس او اكثر من الوجوه ");
else
q.setText("حسحس حزين لانه سيبقى لمده اسبوعين بدون حليب. انت بلا فائده ") ;
center.add(q);
end.setLayout(new GridLayout(1,2));
end.add(menue); end.add(exit);
w.setLayout(new BorderLayout());
w.add(top, BorderLayout.NORTH);
w.add(center, BorderLayout.CENTER);
w.add(end, BorderLayout.SOUTH);
}
}
});
no.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(counter == 0)
{
q.setText("عدد المدن المقدسه في المملكه 3 مدن ");
counter++;
center.add(l1); count++;
}
else if(counter == 1)
{
q.setText("اول اولاد ادم هو قابيل ");
center.add(l1);
count++;
counter++;
}
else if (counter == 2)
{
q.setText("اول ما خلق الله هو الحبر ");
counter++;
}
else if(counter == 3)
{
q.setText("اول من قدم للمدينه هو مصعب بن عمير ");
counter++;
center.add(l1); count++;
}
else if(counter == 4)
{
q.setText("الحيوان الذي ينام على ظهره هو الثعبان");
counter++;
}
else if(counter == 5 )
{
q.setText("الغشاء الذي يغطي العين هو القرنيه ");
counter++;
center.add(l3);
count++;
}
else if(counter == 6)
{
q.setText("توجد اطول شجره في العالم في ايطاليا ");
counter++;
}
else if(counter == 7)
{
q.setText("ام قشعم هي انثى النسر ");
counter++;
center.add(l3);
count++;
}
else if(counter == 8 )
{
q.setText("الهاتف يسمع ولا يتكلم ");
counter++;
}
else if(counter == 9 )
{
q.setText("لا يوجد في الاسفنج اي ثقوب ");
counter++;
center.add(l1); count++;
}
else if(counter == 10 )
{
q.setText("يعيش الجمل لمده 25 سنه ");
counter++;
center.add(l2);
count++;
}
else
{
counter++;
}
if(counter >= 11)
{
w.removeAll(); top.removeAll();
center.removeAll(); end.removeAll();
setLocationRelativeTo(null);
top.setLayout(new GridLayout(1,2));
top.add(l2) ; top.add(l1);
if(count >=5)
q.setText("حسحس يقول لك شكرا لانك جمعت خمس او اكثر من الوجوه ");
else
q.setText("حسحس حزين لانه سيبقى لمده اسبوعين بدون حليب. انت بلا فائده ") ;
center.add(q);
end.setLayout(new GridLayout(1,2));
end.add(menue); end.add(exit);
w.setLayout(new BorderLayout());
w.add(top, BorderLayout.NORTH);
w.add(center, BorderLayout.CENTER);
w.add(end, BorderLayout.SOUTH);
}
}
});
}
}
class test
{
public static void main(String [] args)
{
hashasgame x = new hashasgame ();
x.setVisible(true);
}
}
وشكرا
