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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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