بسم الله الرحمن الرحيم
اخواني واخواتي الاعزاء
السلام عليكم
الرجاء من لديه القدره على شرح هذا البرنامج يتفضل مشكورا
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class GridLabelButtons extends JFrame implements ActionListener
{
private JPanel p;
private JLabel l;
public GridLabelButtons()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p = new JPanel();
p.setLayout(new GridLayout(2,2,20,20));
p.setPreferredSize(new Dimension(200,100));
setContentPane(p);
JButton r = new JButton("Red");
r.addActionListener(this);
p.add®;
JButton a = new JButton("Amber");
a.addActionListener(this);
p.add(a);
JButton g = new JButton("Green");
g.addActionListener(this);
p.add(g);
l = new JLabel("");
p.add(l);
}
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
l.setText(command);
if (command.equals("Red"))
p.setBackground(Color.red);
else if (command.equals("Amber"))
p.setBackground(Color.orange);
else if (command.equals("Green"))
p.setBackground(Color.green);
}
public static void main(String args[])
{
GridLabelButtons f = new GridLabelButtons();
f.pack();
f.show();
}
}
//grid layout panel
وجزاكم الله خيرا