Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Draw a randombox with the following features. *When the program begins, it creat

ID: 3619241 • Letter: D

Question

Draw a randombox with the following features.
*When the program begins, it creates a filled rectangle ofrandom size (make your limits 20-120 pixels) centered on thescreen *When the mouse is clicked, the console reports the dimensionsand location of the box *When the mouse exits the window, the box disappears *When the mouse re-enters the window, it generates a new sizefor the box and recenters it on the screen
b) Modify the above code so that it generates a random colorin addition to the random size for the box. Add code so that thered, green, and blue color components are reported in the consoleas well. Make sure your box has a frame so that it can be seen evenif it is given a very light color.
*When the program begins, it creates a filled rectangle ofrandom size (make your limits 20-120 pixels) centered on thescreen *When the mouse is clicked, the console reports the dimensionsand location of the box *When the mouse exits the window, the box disappears *When the mouse re-enters the window, it generates a new sizefor the box and recenters it on the screen
b) Modify the above code so that it generates a random colorin addition to the random size for the box. Add code so that thered, green, and blue color components are reported in the consoleas well. Make sure your box has a frame so that it can be seen evenif it is given a very light color.

Explanation / Answer

please rate - thanks CRAMSTER rule, 1 question per post, part b, is a new question import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class mouseexp extends Applet implements MouseListener {Random generator = new Random();   private int width, height,x,y,size=500,n=1; public void init()    {    setSize(size, size);    width=generator.nextInt(100)+20;    height=generator.nextInt(100)+20;    x=size/2-(height/2);    y=size/2-(width/2);    setBackground (Color.red);    addMouseListener(this);       } public void mouseEntered(MouseEvent e)     {n=3;    repaint();       } public void mouseClicked(MouseEvent e)     {System.out.println("Box Location: x="+x+", y= "+y);       System.out.println("Box size: width= "+width+", height= "+height);      System.out.println("Window size: "+size+" square");          } public void mouseExited(MouseEvent e)      {n=2;    repaint();       } public void mousePressed(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){} public void mouseReleased(MouseEvent e){ repaint();} public void paint(Graphics g) {switch(n)    {case 3:width=generator.nextInt(100)+20;             height=generator.nextInt(100)+20;             x=size/2-(height/2);             y=size/2-(width/2);         case 1:             g.setColor(Color.white);             g.fillRect(x, y, width, height);               break;    case 2:             break;    } g.setColor(Color.black); g.drawRect(0,0,size,size);    } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote