Sept. 18, 2002
Lesson4.javafrom the web page. Create a
Lesson4project and try it out.
MyPanelobject in your applet which will appear on the right or ``east'' border of the applet.
MyPanelclass so that the constructor takes 4
Stringarguments which specify the labels of the four buttons. Change the applet so that the buttons on the first panel are still labeled ``1'', ``2'', ``3'', ``4'' but the buttons on the second panel are labeled ``A'', ``B'', ``C'', ``D''. Notice that all that changes in your applet is how you call the constructor for
MyCanvaswhich extends the
Canvasclass. (A canvas is a container which has a
paintmethod with which you can add graphics.) Your class should have a constructor function which simply sets the canvas background to yellow. Your class should also have a public paint method which draws a red circle somewhere on the canvas. Now in your applet, create a
MyCanvasobject and add the object to the center of the applet. (Look up how you add to the center with the
MyCanvasso that the circle is always drawn in the center of the canvas (even when the canvas is resized!). To do this you need to determine the size of the canvas within the
paint()method. The method
Dimensionobject indicating the size of the container.
Look up the
Dimension class in the documentation and see if you can
figure out how to do this more challenging problem.