Do the following 3 exercises, each involving the use of painting with Graphics and/or Graphics2D class features. Note that each of these should be set up like the examples we saw in class -- the drawings should be done on a custom JPanel that is embedded as the content area of a JFrame.
The triangle endpoints should be chosen chosen so that they could be
any valid points within the JPanel. Note that this is not always in a
range of 500 x 500 -- if the application frame is expanded, the panel area
will be larger. Do your drawing in method paintComponent.
(Notice that this means that refreshes to the panel will result in new
random trangles. For example, resize the window and the internal
components will be redrawn, because paintComponent will be called
again).
For the drawing of the ovals, follow these rules:
For the refresh of the screen, you'll need to use class javax.swing.Timer. This class sets up a timer event so that the actionPerformed gets called after a given fixed time interval. In your actionPerformed method, you can simply call repaint() on your panel, and a new set of ovals will be drawn.
See this example for an illustration on the usage of the Timer class:
Bouncing Ball
java Triangles java Snowman java ScreenSaverAs usual, submit your jar file through the Canvas submission link.