Write a screen saver program that generates random shapes

Assignment Help Basic Computer Science
Reference no: EM13306137

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 have a JFrame member variable.
  4. 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.
  5. 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.
  6. 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.
  7. Create a private method that returns a random color whenever called that can be any possible random color value. This method will be called from your paintComponent method and from your KeyListener event handler as described below.
  8. Your paintComponent method must use at least four different shapes that you randomly select from... oval, rectangle, filled ovals, filled rectangles, polygons, lines, etc.
  9. The size and position of the shapes that you draw must vary based on the size of the screen. 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.

Reference no: EM13306137

Questions Cloud

Calculate the rate at which the sun is losing mass : Like all stars, our sun converts mass into energy which radiates (spherically) in all directions. Calculate the rate at which the sun is losing mass
How much nitrogen is vaporized : A 55 g piece of aluminum at 21 °C is cooled to -196 °C by placing it in a large container of liquid nitrogen at that temperature. How much nitrogen is vaporized
Draw the 5 stress-elements using the natural orientations : Consider the simply supported beam that has one external load applied to it. At a cross- section that cuts through the carriage bolt, there are 5 points at which the states of stress must be identified.
Describe a societal issue related to cloning : Explain why the phenotype of the cloned mammoth would be similar to the woolly mammoth and not to the elephant egg donor or surrogate elephant mother
Write a screen saver program that generates random shapes : 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 describ..
Find the speed of the approaching police car : Two police cars have identical sirens that produce a frequency of 560 Hz. Find the speed of the approaching police car
How fast was it traveling when it reached the bottom : In the Blackhawk landslide in California, a mass of rock and mud fell 465 m down a mountain and then traveled 8.3 km across a level plain. How fast was it traveling when it reached the bottom
Write a program that can be used to assign seats : Write a program that can be used to assign seats for a commcommercial airplane. The airplane has 13 rows, with 6 seats in each row. Rows 1 and 2 are first class, rows 3 to 7 are business class, and rows 8 to 13 are economy class
What intensity of light emerges : The unpolarized light of intensity I(not) is passed through two polarizers with axes oriented at 30degrees from each other. What intensity of light emerges

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Does your company use both lan and wan technologies

Could any of the technologies (Ethernet, token ring, fast Ethernet, 100VG-AnyLAN or gigabit Ethernet) improve your current network's performance?

  The initialization program

The initialization program will start with how much you have in the cash register and in what denominations the money is in.

  Create an html5 document that contains an unordered list

Create an HTML5 document that contains an unordered list with links to the following examples headings, email, images as hyperlink these are from textbook, special characters, tables, HTML5 forms, and internal links to be included.

  Write a program to determine the answers of the square root

How do you write a program to determine the answers of the square root of 30, the sine and cosine of 100, the value of the floor, ceiling, and round of 44.7, and the larger and the smaller of the character K and the integer 70? In Java code

  Describe why analyst needs to understand how people think

Describe why an analyst requires to understand how people think, how they learn, how they react to change, how they communicate, and how they work.

  What would be the best choice of the degree

A B+ - tree index is to be built on the name attribute of the relation student

  Explain findings-conducting internet search for for cde file

Network asminisrator mentions that other "CDE" files have been sent through the FTP server to another site. Explain your findings after conducting the internet search for "CDE" files.

  Write a select statement that returns four columns

Write a SELECT statement that returns four columns: VendorName

  Should employees be allowed to text message

Should employees be allowed to text message each other during the meeting? As a manager, are there concerns you might have if employees have digital cameras on their cell phones? Read the responses of a few of your classmates. Do you agree with th..

  Explaining geographical information systems

Considering this, explain in scholarly detail some suitable examples of geographical information systems and how they are utilized in supporting both marketing and sales.

  Evaluate the technology, connectivity

Your company has assigned you the task of evaluating its computer networks. You are to write a memo covering 15 points on which you will evaluate the technology, connectivity, and functioning of the company's computer networks.

  Future applications will change manufacturing industry

Prepare a response which explains the future applications which will change manufacturing industry, judiciary, and field of sports. Explain at least one application for each field.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd