MySecondButton

The applet MySecondButton.java demonstrates further the GUI and nesting of Containers.

Two buttons are placed in the North position of the main applet components, and our DrawingPanel.java object, an extension of a Canvas object, is placed in the Center position. As with the previous examples, the main applet is implements ActionListener, and registers with the buttons to received the ActionEvents. When it gets them, it calls into the DrawingPanel that the button was pushed and the DrawingPanel does the rest.

To get two buttons in the North position we do not add the two button directly. First we create a container for the buttons, add the buttons to the container, and add the container to the North position of the applet. The container object is a java.awt.Panel. The default Layout Manager of a Panel is the FlowLayout, which adds the buttons left to right at the natural size.