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

سؤال في GUI

مغلق
بدأه nwa في 13 أبريل 2007 · 7 رد · 898 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته.....

الأخوه والأخوات أغضاء منتدى الجافا.....

لدي سؤال بخصوص GUI؟؟؟

وهو عندما أنشئ Panel وأضيف بعض الــــButton لها وعند الضغط على Button معين منها أريد أن أقوم بمهمه معينه مثل أن يظهر لي Textfield مثلاً

أريد أن أعرف كيف يتم التفاعل بين button وظهور حقل الكتابه

وشكراً

#2

In Button u must register an action(click) and inside action code write code for update jtext properties, than update jtextbox

winter-main.jpg

6179.gif

#3

مشكور يأخ yadoo86 على الرد........

ولكن عندما أضيف الـــــ event المعين إلى الـــ Actionlistener مايصير أي تفاعل ....

هل من حل لذلك؟؟!!

#4

Can u paste Java code?? to find error or mistake part

Thanks for your cooperations

winter-main.jpg

6179.gif

#5

مشكور يأخ yadoo86 على مساعدتك وتفاعلك.... جعل الله ذلك في موازين حسناتك..

وهذا هو الكود...

public class Panel extends JFrame

{

private JButton buttons[];

private Color color =Color.LIGHT_GRAY;

private JPanel buttonJPanel;

Graphics g;

public Panel()

{

super("Drowing");

ButtonHandler handler=new ButtonHandler();

JComboBox text= new JComboBox();

text.addItem("Font");

text.addItem("Size");

text.addActionListener(handler);

JButton rect = new JButton("Rectangle");

rect.addActionListener(handler);

JButton oval = new JButton("Oval");

oval.addActionListener(handler);

JButton line = new JButton("Line");

line.addActionListener(handler);

JPanel bottom = new JPanel();

bottom.setLayout(new GridLayout(1,4));

bottom.add(rect);

bottom.add(oval);

bottom.add(line);

bottom.add(text);

add(bottom, BorderLayout.NORTH);

}

private class ButtonHandler implements ActionListener

{

Graphics g;

ButtonHandler()

{

setBackground(Color.white);

}

public void actionPerformed(ActionEvent evt)

{

String command = evt.getActionCommand();

if (command.equals("Rectangle"))

paintComponent(g);

else if (command.equals("Oval"))

paintComponent(g);

else if (command.equals("Line"))

paintComponent(g);

}

void paintComponent(Graphics g)

{

g.setColor(Color.BLUE);

g.fillRect(100,40,90,55);

g.setColor(Color.black);

g.drawRect(5,40,90,55);

g.setColor(Color.RED);

g.fillOval(290,100,90,55);

g.drawOval(195,140,90,55);

g.setColor(Color.RED);

g.drawOval(5,40,390,55);

}

}//end ineer class

}//end outer class

#6

لم اعرف المشكلة التي تريد حلها ولكن احب ان اذكر بانه

في الكود التالي

تقوم بإرسال المتغير g الى الطريقة paintComponent وقيمته null

public void actionPerformed(ActionEvent evt)
{
String command = evt.getActionCommand();
if (command.equals("Rectangle"))
paintComponent(g);
else if (command.equals("Oval"))
paintComponent(g);
else if (command.equals("Line"))
paintComponent(g);
}

اما اذا رغبت في تحديث JPanel او بعد اضافات مكونات جديده له، يمكنك استخدام الطريقة ()jPanel1.validate

لتتمكن من اظهارها.

#7

مشكور يأخ ali7876 على ردك وتفاعلك جعل الله ذلك في موازين حسناتك....

ولكن الحمد الله عرفت المشكله وتم حلها....

#8
nwa كتب:
مشكور يأخ yadoo86 على مساعدتك وتفاعلك.... جعل الله ذلك في موازين حسناتك..

وهذا هو الكود...

  public class Panel extends JFrame
   {
	  private JButton buttons[];
	  private Color color =Color.LIGHT_GRAY;
	  private JPanel buttonJPanel;
	   Graphics g;


	   public Panel()
	  {
		 super("Drowing");


   	ButtonHandler handler=new ButtonHandler(); 

	  JComboBox text= new JComboBox();  
	  text.addItem("Font");
	  text.addItem("Size");

	  text.addActionListener(handler);

	  JButton rect = new JButton("Rectangle");	
	  rect.addActionListener(handler);

	  JButton oval = new JButton("Oval");
	  oval.addActionListener(handler);

	  JButton line = new JButton("Line");
	  line.addActionListener(handler);

	  JPanel bottom = new JPanel();   
	  bottom.setLayout(new GridLayout(1,4));
	  bottom.add(rect);
	  bottom.add(oval);
	  bottom.add(line);
	  bottom.add(text);

	  add(bottom, BorderLayout.NORTH);

	 }

	 private class ButtonHandler implements ActionListener
	  {
		   Graphics g;

			ButtonHandler()
			{
			  setBackground(Color.white);
			}


			public void actionPerformed(ActionEvent evt)
			  {
			  String command = evt.getActionCommand();
			if (command.equals("Rectangle"))
			   paintComponent(g);
			else if (command.equals("Oval"))
			   paintComponent(g);
			else if (command.equals("Line"))
				paintComponent(g);
				  }


			void paintComponent(Graphics g)
			{


			   g.setColor(Color.BLUE);
			g.fillRect(100,40,90,55);
			g.setColor(Color.black);
			g.drawRect(5,40,90,55);


			g.setColor(Color.RED);
			g.fillOval(290,100,90,55);
			g.drawOval(195,140,90,55);



			g.setColor(Color.RED);
			g.drawOval(5,40,390,55);

			  }

	  }//end ineer class  

[

}//end outer class

هذا الموضوع مغلق.

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