SlideShare ist ein Scribd-Unternehmen logo
1 von 3
SOLUTIONJUG.COM
CLICK HERE TO GET THE SOLUTION !!!!!
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 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.
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();
}
}
Screenshot 1
Screenshot 2
Screenshot 3
CLICK HERE TO GET THE SOLUTION !!!!!

Weitere ähnliche Inhalte

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Comp 274 week 5 programming assignment

  • 1. SOLUTIONJUG.COM CLICK HERE TO GET THE SOLUTION !!!!! 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 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.
  • 2. 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 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 {
  • 3. public void keyPressed(KeyEvent e) { // Terminate the program. System.exit(0); } } public static void main(String[] args) { FullSize obj = new FullSize(); } } Screenshot 1 Screenshot 2 Screenshot 3 CLICK HERE TO GET THE SOLUTION !!!!!