Java Reference
In-Depth Information
8. private Button redBtn, whiteBtn, blueBtn;
9. {
10. redBtn = new Button(“Red”);
11. whiteBtn = new Button(“White”);
12. blueBtn = new Button(“Blue”);
13. }
14.
15. private static final Color RED, WHITE, BLUE;
16.
17. static {
18. RED = new Color(255,0,0);
19. WHITE = new Color(255,255,255);
20. BLUE = new Color(0,0,255);
21. }
22.
23. private class MyButtonListener implements ActionListener {
24. public void actionPerformed(ActionEvent e) {
25. String label = e.getActionCommand();
26. if(label.equals(redBtn.getLabel())) {
27. ColorChanger.this.setBackground(RED);
28. } else if(label.equals(whiteBtn.getLabel())) {
29. ColorChanger.this.setBackground(WHITE);
30. } else if(label.equals(blueBtn.getLabel())) {
31. ColorChanger.this.setBackground(BLUE);
32. }
33. }
34. }
35.
36. public static Color [] getColors() {
37. Color [] colors = {RED, WHITE, BLUE};
38. return colors;
39. }
40.
41. public Button [] getButtons() {
42. Button [] buttons = {redBtn, whiteBtn, blueBtn};
43. return buttons;
44. }
45.
46. public ColorChanger(String title) {
47. super(title);
Search WWH ::




Custom Search