Java Reference
In-Depth Information
9. public class CounterPanel extends JPanel {
10.
11.
private CounterModel counter;
12.
private JLabel valueLabel;
13.
14.
public CounterPanel() {
15.
counter = new CounterModel();
16.
17.
BorderLayout bordLay = new BorderLayout();
18.
this. setLayout(bordLay);
19.
20.
JButton upButton = new JButton("Up");
21.
JButton downButton = new JButton("Down");
22.
valueLabel = new JLabel(""+counter.getValue(),SwingConstants.CENTER);
23.
24.
this .add(upButton,BorderLayout.WEST);
25.
this .add(downButton,BorderLayout.EAST);
26.
this .add(valueLabel,BorderLayout.CENTER);
27.
28.
// The next three lines will later be used to incorporate
// the listener.
29.
// CounterListener countList = new CounterListener(this);
30.
// upButton.addActionListener(countList);
31.
// downButton.addActionListener(countList);
32. }
33.
34. public void increment(){
35.
counter.increment();
36.
valueLabel.setText(""+counter.getValue());
37. }
38.
39. public void decrement(){
40.
counter.decrement();
41.
valueLabel.setText(""+counter.getValue());
42. }
43. }
File: its/CounterGUI/CounterFrame.java
1. package its.CounterGUI;
2.
3. import javax.swing.JFrame;
4. import java.awt.BorderLayout;
5. import its.SimpleFrame.SimpleFrame;
6.
Search WWH ::




Custom Search