Java Reference
In-Depth Information
16.
this .getContentPane().setLayout( new GridLayout(4,1));
17.
redPanel
= new JPanel();
18.
orangePanel = new JPanel();
19.
greenPanel = new JPanel();
20.
JButton nextButton = new JButton("Next");
21.
LightListener lightList = new LightListener( this );
22.
nextButton.addActionListener(lightList);
23.
24.
25.
this .getContentPane().add(redPanel);
26.
this .getContentPane().add(orangePanel);
27.
this .getContentPane().add(greenPanel);
28.
this .getContentPane().add(nextButton);
29.
System.out.println("c="+light.getCurrentColors());
30.
setColor(light.getCurrentColors());
31.
this .repaint();
32.
}
33.
34.
35.
private void setColor( int color){
36.
switch (color) {
37.
case Constants.LIGHT_RED:
38.
redPanel.setBackground(Color.red);
39.
orangePanel.setBackground(Color.lightGray);
40.
greenPanel.setBackground(Color.lightGray);
41.
break ;
42.
case Constants.LIGHT_RED_ORANGE:
43.
redPanel.setBackground(Color.red);
44.
orangePanel.setBackground(Color.orange);
45.
greenPanel.setBackground(Color.lightGray);
46.
break ;
47.
case Constants.LIGHT_GREEN:
48.
redPanel.setBackground(Color.lightGray);
49.
orangePanel.setBackground(Color.lightGray);
50.
greenPanel.setBackground(Color.green);
51.
break ;
52.
case Constants.LIGHT_ORANGE:
53.
redPanel.setBackground(Color.lightGray);
54.
orangePanel.setBackground(Color.orange);
55.
greenPanel.setBackground(Color.lightGray);
56.
break ;
57.
default :
58.
System.out.println("ERROR: ILLEGAL COLOR COMBINATION!");
59.
break ;
60.
}// Switch
61.
}
Search WWH ::




Custom Search