Comp 274 Week 5 Essay

712 Words Sep 1st, 2014 3 Pages
HELPIDO.COM

-------------------------------------------------------
Follow this link to get the tutorial

http://helpido.com/comp-274-week-5-3/
-------------------------------------------------------

COMP 274 - Week 5 Programming Assignment
________________________________________
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.
Requirements:
1. You can NOT use loops of any kind in this program.
2. Your member variables must be private.
3. Your screen saver class must inherit from the JPanel class and it must
…show more content…
At least part of each shape drawn must be visible on the screen.
10. Make your screen saver the full size of the screen.
11. Add a KeyListener to your frame. The KeyListener must handle KeyPressed events.
12. Your KeyListener must call System.exit when the ‘e’ key is pressed.
13. When the ‘s’ key is pressed, your KeyListener must change the size of the window from full screen size to half size (half the width and height of the screen), or from half size back to full size. That is, each time the ‘s’ key is pressed the size of the display toggles between full and half size. This requires changing the size of the frame and calling repaint. HINT: Remember, in order to get the background to be redrawn, you will need to set count back to 0.
14. When the ‘c’ key is pressed, your KeyListener must change the color of the background of the display to a random color. This means it must get a new random color and call the setBackground with the new random color. It must then call repaint as well. HINT: Remember, in order to get the background to be redrawn, you will need to set count back to 0. The following example program illustrates how to create a frame the size of the screen and how to kill the program when any key is pressed. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class FullSize extends JPanel
{
private JFrame frame = new

Related Documents