الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف احدث الفورم

بدأه ms.roben في 17 يوليو 2011 · 11 رد · 692 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

سؤالي في 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);
    }
}


وشكرا
#2

استخدم الداله repaint بعد ان تقوم بحذف او اضافه المكونات

وان لم تنجح معك ارفع المشروع كاملا بالصور

Software Developer
Mahmoudkelany.com


 

#3

الدالة repaint لإعادة الرسم

والدالة invalidate لإعادة بناء الهيكل الشجري للمكونات (بمعنى لو أضفت مكونات أو حذفت مكونات استخدم هذه الدالة)

تحياتي

1
حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#4

اخ علاء جربت الداله الي كتبتها بس ما انحلت المشكله

وهذا المشروع كامل رفعته

http://www.up-00.com/dldE9j77204.rar.html

#5

الملف مش بيتحمل

ممكن ترفعه على احدى مواقع الرفع المعروفه مثل

www.mediafire.com

على العموم استخدم هذه

  SwingUtilities.updateComponentTreeUI(this);

وان شاء الله هتعمل معاك

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 18 يوليو 2011 في 13:54

Software Developer
Mahmoudkelany.com


 

#6
اقتباس

SwingUtilities.updateComponentTreeUI(this);

هذه لتحديث ال Look and Feel

استخدم validate

اقتباس

validate

public void validate()

Validates this container and all of its subcomponents.

The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.

If this Container is not valid, this method invokes the validateTree method and marks this Container as valid. Otherwise, no action is performed.

Overrides:

validate in class Component

See Also:

add(java.awt.Component), Component.invalidate(), JComponent.revalidate(), validateTree()

تم تعديل هذه المشاركة بواسطة MOHAMED FATHEI في 19 يوليو 2011 في 09:00


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#7

ممكن توضحى ايه اللى بيحصل بالظبط

واين تردين تحديث الFrame ؟؟ بعد ما بيحصل ايه ؟؟

Software Developer
Mahmoudkelany.com


 

#8

انا جربت داله validate بس ما نفعت

رفعته على ميديا فير

http://www.mediafire.com/?h1n9e4uyl73zrs0

#9

هو ذحين فيه زر اسمه نكست يوم اضغط عليه تروح الصوره الي كانت موجوده وتوضع صوره اخرى وكمان التكست يتغير لجمله ثانيه لكن يوم اعمل رن ما تحدث هذي الثغييرات

الا اذا في الكود حطيت

setSize و غيرت حجم الفريم عن الحجم السابق

او اذا صغرت النافذه وكبرتها فيحدث التغييير الي في الفريم

انا ابغاه التغيير يحدث بدون ما اغير السايز او اصغر واكبر

اتمنى فهمتوا الي ابغاه :(

#10

جربى كدا

يارب اكون فهمت قصدك

package ex5;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import sun.audio.*;
import java.io.*;
/*
 *
 * author  Asmaa assulami
 *
 */

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);
            	invalidate();
        	}
    	});
    	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);
            	}
            	SwingUtilities.updateComponentTreeUI(w);
        	}
    	});


    	startplaying.addActionListener(new ActionListener() {

        	public void actionPerformed(ActionEvent e) {
            	counter = 0;
            	count = 0;
            	w.removeAll();
            	top.removeAll();
            	center.removeAll();
            	end.removeAll();
            	setExtendedState(Frame.MAXIMIZED_BOTH); // full screen
            	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);
            	invalidate();
        	}
    	});
    	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);
                	setExtendedState(Frame.MAXIMIZED_BOTH); // full screen

            	}
            	invalidate();
        	}
    	});
    	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);
                	setExtendedState(Frame.MAXIMIZED_BOTH); // full screen
            	}
            	invalidate();
        	}
    	});
	}
}

class test {

	public static void main(String[] args) {
    	hashasgame x = new hashasgame();
    	x.setVisible(true);
	}
}

Software Developer
Mahmoudkelany.com


 

#11

فقط قم باستبدال كل invalidate بالأمر validate وسيعمل برنامجك

597657.png
#12

شكرااااااااااااااااااااااااا كثيييرااا اتحلت معي المشكله

اخ Mahmoud Kelan

جزااااك الله خيرررررررر

جربت كل الي فوق الي نفع معاي كانت هذي الجمله

SwingUtilities.updateComponentTreeUI(w);

و الشكر لكم جميعا ايضا

مواضيع مشابهة