Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP: Add methods to the Picture class that: Populate the window with pixels in shades of gray (from white to black, in gradations across

JAVA HELP:

Add methods to the Picture class that: Populate the window with pixels in shades of gray (from white to black, in gradations across the window), then call validate & repaint ______________________________________ Draw interesting patterns in the window by changing Pixel qualities, then call validate & repaint I leave it up to you to interpret interesting, but I ask that you create at least two unique patterns (using two different methods) first pattern: _________________________________ second pattern: ________________________________

import java.awt.*; public class Pixel { private int red, green, blue, size; private Color color; public Pixel(int r, int g, int b) { red = Math.abs(r % 256); green = Math.abs(g % 256); blue = Math.abs(b % 256); color = new Color(red, green, blue); size = 1; } public Pixel() { this((int)(Math.random()*256), (int)(Math.random()*256), (int)(Math.random()*256)); } public int getRedValue() {return red;} public int getGreenValue() {return green;} public int getBlueValue() {return blue;} public int getSize() {return size;} public void setRedValue(int r) { red = Math.abs(r%256); color = new Color(red, green, blue); } public void setGreenValue(int g) { green = Math.abs(g%256); color = new Color(red, green, blue); } public void setBlueValue(int b) { blue = Math.abs(b%256); color = new Color(red, green, blue); } public void setSize(int s) {size = s;} public Color getColor() { return color; } }

//**************NEW FILE************** import javax.swing.*; import java.awt.*; public class Picture extends JFrame { private Pixel [][] elements; boolean square = false; public Picture(int size) { elements = new Pixel[size][size]; for (int x=0; x

public Picture() { this(500); } public void turnBlack() { for(int x=0; x

//*****************NEW FILE*************** import java.util.*;

public class ShowPic { public static void main(String [] args) throws InterruptedException { Picture p = new Picture(); Scanner kb = new Scanner(System.in); int waitTime; System.out.println("Enter number of seconds to view each picture: "); waitTime = kb.nextInt() * 1000; Thread t = new Thread(); p.setVisible(true); t.sleep(waitTime); p.setVisible(false); p.turnBlack(); p.setVisible(true); t.sleep(waitTime); p.setVisible(false); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions