hey guys it's me again,well i designed one program but could you help me in correcting it because it has too many errors. well the requirements is written below:
design a GUI that contains two rows of JButtons with three buttons in each row the buttons in the top row are labelled Red, Yellow, and Green.the buttons in the bottom row are labelled Stop, Look and Go.Iniatially, all buttons inthe top row are white.When the user clicks on the Stop button, the Red button changes its colour to red and the Yellow and green buttons remain white, Similarly,when the user clicks the Look button the yellow changes it's colur to yellow and the Red and Green buttons become white, and so on.
AND HERE IS MY PROGRAM:
[import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class trafficlights extends JFrame
{
private JButton redB,yellowB,greenB;
private JButton stopB,lookB,goB;
private StopButtonHandler sHandler;
private LookButtonHandler lHandler;
private GoButtonHandler gHandler;
private Container pane;
private static final int WIDTH = 456;
private static final int HEIGHT = 450;
public trafficlights()
{
redB = new JButton("Red", SwingConstants.RIGHT);
yellowB = new JButton("Yellow ", SwingConstants.CENTER);
greenB = new JButton("Green ", SwingConstants.LEFT);
stopB = new JButton("Stop");
sHandler = new StopButtonHandler();
stopB.addActionListener(sHandler);
lookB = new JButton("Look");
lHandler = new LookButtonHandler();
lookB.addActionListener(lHandler);
goB = new JButton("Go");
gHandler = new GoButtonHandler();
goB.addActionListener(gHandler);
Container pane = getContentPane();
pane.setLayout(new GridLayout (6, 3));
pane.add(redB);
pane.add(yellowB);
pane.add(greenB);
pane.add(stopB);
pane.add(lookB);
pane.add(goB);
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class StopButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
redB.setForeground(Stop.red);
}
}
private class LookButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
yellowB.setForeground(Look.yellow);
}
}
private class GoButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
greenB.setForeground(Go.green);
}
}
public static void main(String [] args)
{
trafficlights demoObject = new trafficlights();
}
}
/]