here is the code I have so far:
import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JOptionPane; import java.util.Scanner; public class Program1 extends JFrame { private int x1=100,y1=100,x2=150,y2=200,r1=50,r2=60; boolean check = false; public Program1() { String input = JOptionPane.showInputDialog("Enter the X-Coordinate of circle #1"); x1 = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the Y-Coordinate of circle #1"); y1 = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the X-Coordinate of circle #2"); x2 = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the Y-Coordinate of circle #2"); y2 = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the radius of circle #1"); r1 = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter the radius of circle #2"); r2 = Integer.parseInt(input); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } @Override public void paint(Graphics g) { super.paint(g); g.drawOval(x1-r1, y1-r1, r1*2, r1*2); g.drawOval(x2-r2, y2-r2, r2*2, r2*2); g.drawLine(x1, y1, x2, y2); double areaCircle1 = Math.PI*r1*r1; double circumferenceCircle1 = 2*Math.PI*r1; double areaCircle2 = Math.PI*r2*r2; double circumferenceCircle2 = 2*Math.PI*r2; g.drawString(String.format("Area = %1.3f", areaCircle1), x1, y1); g.drawString(String.format("Circumference = %1.3f", circumferenceCircle1), x1, y1+10); g.drawString(String.format("Area = %1.3f", areaCircle2), x2, y2); g.drawString(String.format("Circumference = %1.3f", circumferenceCircle2), x2, y2+10); double distance = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); { Program1 frame = new Program1(); frame.setSize(500, 500); frame.setVisible(true); } }
Image.jpg
The problem I am having is when I run the program, I need it to put the stats at the top of the window and not in the center of the circles like the image I included says. Can someone post the code for what I need to change please?
[If what I'm asking is confusing, I'll try to re-word it. If you run the program and see that it puts the stats in the center of the circles, I need to know what to change to get it to put the stats at the top of the window, but keep the circles the same like the picture I've included shows.]