Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java Draw circles at end Point of Line with End Points as Centre

  1. Apr 12, 2017 #1
    Hi,

    I am trying to draw circles at the end points of a line but circle centre is not exactly on the end point of the line. Can somebody please guide me.

    import java.applet.Applet;

    import java.awt.*;

    import javax.swing.*;

    public class JCircle extends Applet{

    int x1=30;

    int y1=30;

    int x2=60;

    int y2=60;

    public void paint(Graphics g) {

    g.drawLine(x1, y1,x2, y2);

    g.drawOval( x1, y1, 10, 10);

    g.drawOval( x2, y2, 10, 10);



    }

    }

    Some body please guide me.

    Zulfi.
     

    Attached Files:

  2. jcsd
  3. Apr 12, 2017 #2

    BvU

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Perhaps drawoval doesn't do what you think it does ? Looks to me as if the top left corner appears at (x,y) , not the center....
     
  4. Apr 12, 2017 #3

    Mark44

    Staff: Mentor

    From the documentation for the drawOval() method - ()
    @zak100, please use code tags on your code. They should look like this:
    [code=java]
    Code (Java):
    import java.applet.Applet;
    import java.awt.*;
    import javax.swing.*;
    public class JCircle extends Applet
    {
        int x1=30;
       // etc.
    [/code]
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Draw circles at end Point of Line with End Points as Centre
Loading...