Java Reference
In-Depth Information
figure 11-25
Note
The Swing menu components are used here.
Menu
,
MenuBar
,
MenuItem
,
setMenuBar
, and
getMenuBar
also exist, but these correspond to the AWT
components, which should be considered outdated. The naming is somewhat
confusing, but that's the way it is.
3.
You will have noted that it is possible to assign action listeners to menu items. In this project, the
SimplePaint
class acts as a listener for all menu items as well. The
actionPerformed
method
then determines which method to call based on the action command.
4.
The New menu item performs a simple operation and just calls the
clear
method on the paint
panel.
5.
Loading an image is a bit more convoluted. First, a
JFileChooser
is constructed (you could also
make this a class field; go ahead and try this if you want) and configured so users can only select
Search WWH ::
Custom Search