public class PinkJPanelDemo extends JFrame implements ActionListener
1:
2: import javax.swing.*;
3: import java.awt.*;
4: import java.awt.event.*;
5:
6: /**
7: Simple demonstration of putting buttons in a PinkJPanel.
8: */
9: public class PinkJPanelDemo extends JFrame implements ActionListener
10: {
11: public static final int WIDTH = 300;
12: public static final int HEIGHT = 200;
13:
14: public static void main(String[] args)
15: {
16: PinkJPanelDemo guiWithPanel = new PinkJPanelDemo();
17: guiWithPanel.setVisible(true);
18: }
19:
20: public PinkJPanelDemo()
21: {
22: setSize(WIDTH, HEIGHT);
23: addWindowListener(new WindowDestroyer());
24: setTitle("Panel Demonstration");
25: Container contentPane = getContentPane();
26: contentPane.setBackground(Color.BLUE);
27: contentPane.setLayout(new BorderLayout());
28:
29: PinkJPanel buttonPanel = new PinkJPanel();
30:
31: buttonPanel.setLayout(new FlowLayout());
32:
33: JButton stopButton = new JButton("Red");
34: stopButton.setBackground(Color.RED);
35: stopButton.addActionListener(this);
36: buttonPanel.add(stopButton);
37:
38: JButton goButton = new JButton("Green");
39: goButton.setBackground(Color.GREEN);
40: goButton.addActionListener(this);
41: buttonPanel.add(goButton);
42:
43: contentPane.add(buttonPanel, BorderLayout.SOUTH);
44: }
45:
46: public void actionPerformed(ActionEvent e)
47: {
48: Container contentPane = getContentPane();
49:
50: if (e.getActionCommand().equals("Red"))
51: contentPane.setBackground(Color.RED);
52: else if (e.getActionCommand().equals("Green"))
53: contentPane.setBackground(Color.GREEN);
54: else
55: System.out.println("Error in button interface.");
56: }
57: }