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

<h3>Details</h3> <p>The DrawingPanel should be 400x300.</p> <h4>Circles</h4> <p>

ID: 3623949 • Letter: #

Question

<h3>Details</h3>
<p>The DrawingPanel should be 400x300.</p>
<h4>Circles</h4>
<p>Ask the user for the center and radius of each circle.&#160; Use the&#160;<tt>fillOval</tt>&#160;method to draw the circles.&#160; Note that the parameters to&#160;<tt>fillOval</tt>&#160;(the upper-left corner and the width and height of the bounding box) need to be calculated from the information provided by the user (the center and the radius).&#160; Also, fill the circles using three different colors.</p>
<h4>Information</h4>
<p>Use&#160;<tt>println</tt>&#160;statements to provide information about the circles.&#160; Remember to put the results of the&#160;<tt>println</tt>&#160;statements into a file named&#160;<tt>CirclesOutput.txt</tt>.&#160; Each of the following items should be performed by a separate static method.&#160; Each method might have up to six parameters.&#160; Each circle is described by three values: the x and y values of the center, and the radius.</p>
<ol>
<li>Given two circles, return&#160;<tt>-1</tt>&#160;if the first circle is smaller, return&#160;<tt>0</tt>&#160;if the two circles have the same size, or return&#160;<tt>1</tt>&#160;if the first circle is larger.&#160; The program should print a line of output like:
<blockquote>
<pre>The green circle is smaller than the red circle.
</pre>
</blockquote>
</li>
<li>Given two circles, return&#160;<tt>1</tt>&#160;if the circles intersect or return&#160;<tt>0</tt>&#160;if the circles do not intersect (alternatively, you could return&#160;<tt>true</tt>&#160;or&#160;<tt>false</tt>).&#160; If&#160;<tt>(x1,y1)</tt>&#160;and&#160;<tt>(x2,y2)</tt>&#160;are the centers of the circles and if&#160;<tt>r1</tt>&#160;and&#160;<tt>r2</tt>&#160;are their radiuses, then the circles intersect if the distance between the centers, the square root of
<blockquote>
<pre>(x1 - x2)<sup>2</sup> + (y1 - y2)<sup>2</sup>
</pre>
</blockquote>
is less than or equal to&#160;<tt>r1 + r2</tt>.&#160; The program should print a line of output like:
<blockquote>
<pre>The blue circle intersects the red circle.
</pre>
</blockquote>
</li>
<li>(Optional) Given a circle, return&#160;<tt>1</tt>&#160;if the circle is completely within the window, return&#160;<tt>0</tt>&#160;if the circle is partially within the window, or return&#160;<tt>-1</tt>&#160;if the circle is completely outside the window.&#160; The program should print something appropriate.</li>
</ol>
<p>Note that each method needs to be called three times.&#160; If your circles are blue, green, and red, then the first method needs to be called for three pairs: blue and green, blue and red, and green and red.</p>
<p>If you find it is more convenient to return values other than&#160;<tt>-1</tt>,&#160;<tt>0</tt>, and&#160;<tt>1</tt>, you are free to do so.&#160; However, your methods must return values that your main method uses to produce the text output.&#160; You are also free to implement any additional methods that you like.</p>
<p>&#160;</p>
<p>Here is the code for &#160;the drawing pannel:</p>
<p>/*Stuart Reges and Marty SteppFebruary 24, 2007Some modifications by Tom Bylander in 2010<br />The DrawingPanel class provides a simple interface for drawing persistentimages using a Graphics object. &#160;An internal BufferedImage object is usedto keep track of what has been drawn. &#160;A client of the class simplyconstructs a DrawingPanel of a particular size and then draws on it withthe Graphics object, setting the background color if they so choose.<br />To ensure that the image is always displayed, a timer calls repaint atregular intervals.*/<br />import java.awt.*;import java.awt.event.*;import java.awt.image.*;import javax.swing.*;import javax.swing.event.*;<br />public class DrawingPanel implements ActionListener {&#160;&#160; &#160;private static final int DELAY = 100; &#160;// delay between repaints in millis&#160;&#160; &#160;private static final boolean PRETTY = false; &#160;// true to anti-alias<br />&#160;&#160; &#160;private int width, height; &#160; &#160;// dimensions of window frame&#160;&#160; &#160;private JFrame frame; &#160; &#160; &#160; &#160; // overall window frame&#160;&#160; &#160;private JPanel panel; &#160; &#160; &#160; &#160; // overall drawing surface&#160;&#160; &#160;private BufferedImage image; &#160;// remembers drawing commands&#160;&#160; &#160;private Graphics2D g2; &#160; &#160; &#160; &#160;// graphics context for painting&#160;&#160; &#160;private JLabel statusBar; &#160; &#160; // status bar showing mouse position<br />&#160;&#160; &#160;// construct a drawing panel of given width and height enclosed in a window&#160;&#160; &#160;public DrawingPanel(int width, int height) {&#160;&#160; &#160; &#160; &#160;this.width = width;&#160;&#160; &#160; &#160; &#160;this.height = height;&#160;&#160; &#160; &#160; &#160;image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);<br />&#160;&#160; &#160; &#160; &#160;statusBar = new JLabel(" ");&#160;&#160; &#160; &#160; &#160;statusBar.setBorder(BorderFactory.createLineBorder(Color.BLACK));<br />&#160;&#160; &#160; &#160; &#160;panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));&#160;&#160; &#160; &#160; &#160;panel.setBackground(Color.WHITE);&#160;&#160; &#160; &#160; &#160;panel.setPreferredSize(new Dimension(width, height));&#160;&#160; &#160; &#160; &#160;panel.add(new JLabel(new ImageIcon(image)));<br />&#160;&#160; &#160; &#160; &#160;// listen to mouse movement&#160;&#160; &#160; &#160; &#160;MouseInputAdapter listener = new MouseInputAdapter() {&#160;&#160; &#160; &#160; &#160; &#160; &#160;public void mouseMoved(MouseEvent e) {&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;statusBar.setText("(" + e.getX() + ", " + e.getY() + ")");&#160;&#160; &#160; &#160; &#160; &#160; &#160;}<br />&#160;&#160; &#160; &#160; &#160; &#160; &#160;public void mouseExited(MouseEvent e) {&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;statusBar.setText(" ");&#160;&#160; &#160; &#160; &#160; &#160; &#160;}&#160;&#160; &#160; &#160; &#160;};&#160;&#160; &#160; &#160; &#160;panel.addMouseListener(listener);&#160;&#160; &#160; &#160; &#160;panel.addMouseMotionListener(listener);<br />&#160;&#160; &#160; &#160; &#160;g2 = (Graphics2D)image.getGraphics();&#160;&#160; &#160; &#160; &#160;g2.setColor(Color.BLACK);&#160;&#160; &#160; &#160; &#160;if (PRETTY) {&#160;&#160; &#160; &#160; &#160; &#160; &#160;g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);&#160;&#160; &#160; &#160; &#160; &#160; &#160;g2.setStroke(new BasicStroke(1.1f));&#160;&#160; &#160; &#160; &#160;}<br />&#160;&#160; &#160; &#160; &#160;frame = new JFrame("Drawing Panel");&#160;&#160; &#160; &#160; &#160;frame.setResizable(false);&#160;&#160; &#160; &#160; &#160;frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&#160;&#160; &#160; &#160; &#160;frame.getContentPane().add(panel);&#160;&#160; &#160; &#160; &#160;frame.getContentPane().add(statusBar, "South");&#160;&#160; &#160; &#160; &#160;frame.pack();&#160;&#160; &#160; &#160; &#160;frame.setVisible(true);&#160;&#160; &#160; &#160; &#160;toFront();<br />&#160;&#160; &#160; &#160; &#160;// repaint timer so that the screen will update&#160;&#160; &#160; &#160; &#160;new Timer(DELAY, this).start();&#160;&#160; &#160;}<br />&#160;&#160; &#160;// used for an internal timer that keeps repainting&#160;&#160; &#160;public void actionPerformed(ActionEvent e) {&#160;&#160; &#160; &#160; &#160;panel.repaint();&#160;&#160; &#160;}<br />&#160;&#160; &#160;// obtain the Graphics object to draw on the panel&#160;&#160; &#160;public Graphics2D getGraphics() {&#160;&#160; &#160; &#160; &#160;return g2;&#160;&#160; &#160;}<br />&#160;&#160; &#160;// set the background color of the drawing panel&#160;&#160; &#160;public void setBackground(Color c) {&#160;&#160; &#160; &#160; &#160;panel.setBackground(c);&#160;&#160; &#160;}<br />&#160;&#160; &#160;// show or hide the drawing panel on the screen&#160;&#160; &#160;public void setVisible(boolean visible) {&#160;&#160; &#160; &#160; &#160;frame.setVisible(visible);&#160;&#160; &#160;}<br />&#160;&#160; &#160;// makes the program pause for the given amount of time,&#160;&#160; &#160;// allowing for animation&#160;&#160; &#160;public void sleep(int millis) {&#160;&#160; &#160; &#160; &#160;panel.repaint();&#160;&#160; &#160; &#160; &#160;try {&#160;&#160; &#160; &#160; &#160; &#160; &#160;Thread.sleep(millis);&#160;&#160; &#160; &#160; &#160;} catch (InterruptedException e) {}&#160;&#160; &#160;}<br />&#160;&#160; &#160;// makes drawing panel become the frontmost window on the screen&#160;&#160; &#160;public void toFront() {&#160;&#160; &#160; &#160; &#160;frame.toFront();&#160;&#160; &#160;}}</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#65279;</p>

Explanation / Answer

import java.awt.*;
import javax.swing.*;

public class Circles extends JFrame
{

private int screen = 160;

public Circles ()
    {
      super("Three Circles")
      setSize( 400, 300 );
      setVisible( true );
     }

public void paint( Graphics g )
    {
     super.paint( g );
    
     for ( int i = 1; i <= 3; i++ )
        {

         int origin = screent + 80 - i * 10;
         g.drawOval( origin, origin, i * 20, i * 20);
         }
    }

public static void main( String[] args)
      {
       Circles c = new Circles ();
       c.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      }

}

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