Be the first to like this
Write a Screen Saver program that generates random shapes of random colors and sizes at random positions within the display area. Add controls so typing different keys on the keyboard cause the window to change size and background color as described below.
You can NOT use loops of any kind in this program.
Your member variables must be private.
Your screen saver class must inherit from the JPanel class and it must have a JFrame member variable.
Your program must keep track of the number of shapes it draws on the screen and after 25 shapes have been drawn, it must clear the screen. This is most easily done by calling the base class (JPanel’s) paintComponent method.
You should use the Timer object to generate ActionEvents to drive your Screen Saver. Set the timer to fire an ActionEvent once a second. This will cause your actionPerformed method execute, which should simply call the repaint method. Calling the repaint method causes your paintComponent method to execute.
Your paintComponent method will do all the work to select a random color, random shape and random position within the boundaries of your panel, and draw that shape, keeping count of the number of shapes which have been drawn.