COMP274 Lab5 – ScreenSaver Program – Guaranteed 100% score

Lab Price = $15
Please feel free to send us your queries at: [email protected]
Payment Methods

Add to Cart

Buy Now

View Cart


Problem Statement

COMP-274
Week 5 Programming Assignment

Write a Screen Saver program that generates shapes of random colors and sizes at random positions within the display area. Add controls so typing different keys on the keyboard control which shape is being randomly drawn, and which 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 every 300 milliseconds. 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 control what is being drawn on the screen. It keeps a counter (member variable) of how many shapes have been drawn on the screen and when the counter hits 25, it calls the base class paintComponent method to erase the display area.
7. Your program will keep a drawingState (member variable). Your paintComponent method will use this to decide which shape is to be drawn on the screen. The states and the shape to be drawn in that state are listed below.

State Shape
1 Ovals
2 Rectangles
3 Lines
4 Arcs

8. Your program MUST HAVE 4 private methods, one for each of the 4 different drawing states. Each of the methods takes a Graphics object as a parameter. The 4 different methods are drawOval, drawRectangle, drawLine, drawArc. When called, each method will generate random position values, random width and height values, and any other random values needed to draw that specific shape. These methods are called from your paintComponent method depending on which drawing state has been selected from the keyboard – explained later. For example, if the drawing state is 1, then paintComponent calls the drawOval method.
9. Each of the 4 drawing methods will need to get a random Color object that determines the color to be used for drawing. This must be done by calling another private method, getRandomColor, that returns a Color object whenever called. This method should generate three random numbers between 1 and 255 and create a Color object using those three random values. This new random color object is returned by this method. This method will also be called from your KeyListener event handler as described below.
10. Make your screen saver the full size of the screen. The technique for how to do this is shown in the code below. A member variable will need to be added to keep track of whether the display area is currently full size or half size (more later).
11. 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. The starting coordinates for each shape should be a random number between 1 and half of the current screen width and height. This guarantees that at least part of your shape will be visible. Your random length and width values should also be scaled by the current length and width of the display.
12. You will need to write an event handler inner class that extends the KeyAdapter class. You will need to add the keyPressed method to handle KeyPressed events.
13. Your event handler class must call System.exit when the ‘x’ key is pressed.
14. When the ‘s’ key is pressed, your event handler 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.
15. When the ‘c’ key is pressed, your event handler must change the color of the background of the display to a random color. This means it must get a new random color by calling the getRandomColor method and then call the panel’s setBackground method with the new color object.
16. The shape to be drawn is controlled by from the keyboard. The following keys control the drawing state:
Key State
‘o’ 1 – ovals
‘r’ 2 – rectangles
‘l’ 3 – lines
‘a’ 4 – arcs
Whenever one of these keys is pressed, the drawing state should be changed.
17. Whenever ANY of these 6 keys are pressed (all but the ‘x’), the counter variable should be set so that the next time paintComponent runs, it will erase the screen, and the repaint method should be called.

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 JFrame(“FullSize”);
private Rectangle rectangle;
boolean full;

FullSize()
{
// Remove the title bar, min, max, close stuff
frame.setUndecorated(true);
// Add a Key Listener to the frame
frame.addKeyListener(new KeyHandler());
// Add this panel object to the frame
frame.add(this);
// Get the dimensions of the screen
rectangle = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
// Set the size of the frame to the size of the screen
frame.setSize(rectangle.width, rectangle.height);
frame.setVisible(true);
// Remember that we are currently at full size
full = true;
}
// This method will run when any key is pressed in the window
class KeyHandler extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
// Terminate the program.
System.exit(0);
}
}
public static void main(String[] args)
{
FullSize obj = new FullSize();
}
}
Take a screen shot of the output of this program. Paste the screen shot and your source code for your program into a Word document. Submit the Word document to the drop box.

Relevant Material
Screenshots
Screenshot1

Screenshot2

Screenshot3

Screenshot4

Instructions
* If you want to purchase multiple products then click on “Buy Now” button which will give you ADD TO CART option.Please note that the payment is done through PayPal.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Payment Details

 

Lab Price = $15
Please feel free to send us your queries at: [email protected]
Payment Methods

Add to Cart

Buy Now

View Cart

Privacy Policy
We take your privacy seriously and will take all measures to protect your personal information.
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
Refund Policy
Incase you face any issues with the tutorial, please free to contact us on [email protected]
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.


Leave a Reply