Java Reference
In-Depth Information
6.
LightFrame lf = new LightFrame(lm);
7.
lf.showIt();
8.
}
9. }
A.2.2
4.3
Here is the code in a non-model-view implementation. It is also in one file and
not documented. It works, but one should not program Java like this.
File: its/ColorSelection/ColorSelectionFrame.java
1. package its.ColorSelection;
2.
3. import javax.swing.*;
4. import java.awt.Color;
5. import java.awt.GridLayout;
6. import its.SimpleFrame.SimpleFrame;
7. import java.awt.event.*;
8.
9.
10.
11.
12. public class ColorSelectionFrame extends SimpleFrame {
13.
14.
private JPanel colPanel;
15.
private JButton redBut, blueBut, yellowBut;
16.
17.
18.
public ColorSelectionFrame() {
19.
blueBut
= new JButton("blue");
20.
redBut
= new JButton("red");
21.
yellowBut = new JButton("yellow");
22.
23.
ColorListener cList = new ColorListener();
24.
blueBut.addActionListener(cList);
25.
redBut.addActionListener(cList);
26.
yellowBut.addActionListener(cList);
27.
28.
colPanel = new JPanel();
29.
colPanel.setBackground(Color.gray);
30.
31.
GridLayout gLayout = new GridLayout(2,2);
32.
this .getContentPane().setLayout(gLayout);
33.
Search WWH ::




Custom Search