Java Reference
In-Depth Information
75
drawSpace.setLevel(level);
repaint();
76
77
}
78
}
79
} // end anonymous inner class
80
); // end addActionListener
81
82
// set up increase level button to add to control panel
83
// and register listener
84
final JButton increaseLevelJButton = new JButton( "Increase Level" );
85
controlJPanel.add(increaseLevelJButton);
86
increaseLevelJButton.addActionListener(
87
new ActionListener() // anonymous inner class
88
{
89
// process increaseLevelJButton event
90
@Override
91
public void actionPerformed(ActionEvent event)
92
{
93
int level = drawSpace.getLevel();
++level;
94
95
96 // modify level if possible
97 if ((level >= MIN_LEVEL )) &&
98 (level <= MAX_LEVEL ))
99 {
100
101
102
103 }
104 }
105 } // end anonymous inner class
106 ); // end addActionListener
107
108 controlJPanel.add(levelJLabel);
109
110 // create mainJPanel to contain controlJPanel and drawSpace
111 final JPanel mainJPanel = new JPanel();
112 mainJPanel.add(controlJPanel);
113 mainJPanel.add(drawSpace);
114
115 add(mainJPanel); // add JPanel to JFrame
116
117 setSize( WIDTH , HEIGHT ); // set size of JFrame
118 setVisible( true ); // display JFrame
119 } // end Fractal constructor
120
121 public static void main(String[] args)
122 {
123 Fractal demo = new Fractal();
124 demo.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
125 }
126 } // end class Fractal
levelJLabel.setText( "Level: " + level);
drawSpace.setLevel(level);
repaint();
Fig. 18.18 | Fractal user interface. (Part 3 of 3.)
Search WWH ::




Custom Search