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

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 2K views
zak100
Messages
462
Reaction score
11
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.
 
Attachments
  • circles not at end points.jpg
    circles not at end points.jpg
    1,003 bytes · Views: 565
Physics news on Phys.org
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...
 
BvU said:
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...
From the documentation for the drawOval() method - ()
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#drawOval(int said:
public abstract void drawOval(int x,
int y,
int width,
int height)
Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments.
The oval covers an area that is width + 1 pixels wide and height + 1 pixels tall.

Parameters:
x - the x coordinate of the upper left corner of the oval to be drawn.
y - the y coordinate of the upper left corner of the oval to be drawn.
width - the width of the oval to be drawn.
height - the height of the oval to be drawn.
@zak100, please use code tags on your code. They should look like this:
Java:
[code=java]import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
public class JCircle extends Applet
{
    int x1=30;
   // etc.
[/code]