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

I am using a simple GUI that draws a tracer point in a window. The method I wrot

ID: 3788314 • Letter: I

Question

I am using a simple GUI that draws a tracer point in a window. The method I wrote above draws a circle in the GUI. I need to find a way to draw another circle, with its center being the point on the circumference of the above circle. So the x and y values I get from the above method should be the center of my new circle. Everything I try seems to only modify the existing circle or make an ellipse I'm so stuck! I asked this on here once and they just pasted my own code as an answer.

public static void drawspiral (Display panel int originx panel .getWidth 2 int originY panel. getHeight 2 double degAng 270 double radius 150 double x y, radAng Centerx, centerY; while true rad Ang degAng Math.PI 180: centerX originx radius Math. .cos radAng centerY origin Y radius Math.. sin (radAng centerX 25 Mat radAng y centerY 2.5 Math Sin radAng panel drawNextPoint (int) centerX (int) centerY degAng 0.45 System. out println "x x y y

Explanation / Answer

Comment : Just run the program below you will get what you wanted. And the trick is in the computeY method in the code below. Commented in the code itself where you required, please check it. All the best.

TwoCircles.java

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Ellipse2D;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class TwoCircles
{
public static void main(String[] args) throws IOException
{
   createAndShowGUI();
}

private static void createAndShowGUI()
{
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new CircleIntersectionPanel());
f.setSize(1000, 1000);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}

class CircleIntersectionPanel extends JPanel
implements MouseMotionListener
{
   private static final long serialVersionUID = 1L;
   private Point mousePosition = null;

CircleIntersectionPanel()
{
addMouseMotionListener(this);
}

@Override
protected void paintComponent(Graphics gr)
{
super.paintComponent(gr);
Graphics2D g = (Graphics2D)gr;

double centerX = getWidth() / 2;
double centerY = getHeight() / 2;
double radius = 200;

g.setStroke(new BasicStroke(2));
g.setColor(Color.BLACK);;
g.draw(new Ellipse2D.Double(
centerX-radius, centerY-radius,
radius+radius, radius+radius));
if (mousePosition == null)
{
return;
}

g.setColor(Color.BLUE);

double x = (mousePosition.x - centerX) / radius;
double y = computeY(x);
//New center calculation
double cx = centerX + radius * x;
double cy = centerY - radius * y;
g.draw(new Ellipse2D.Double(cx-radius/2, cy-radius/2, radius, radius));
}
  
//Used to calculate the point on the circumference of the circle
private static double computeY(double x)
{
return Math.sin(Math.acos(x));
}


@Override
public void mouseMoved(MouseEvent e)
{
mousePosition = e.getPoint();
repaint();
}

@Override
public void mouseDragged(MouseEvent e)
{
}

}

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