...

View Full Version : drawing a curved line between 2 points



nickyfraggle
04-14-2008, 06:08 PM
Hello,

I am trying to draw a curved line between 2 circles.

I'm really not sure how to do this.

I can draw a straight line..

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

Where x1 and y1 are the start co-ordinates and x2 y2 are the finishing ones.

Basically I just want a line that curves between these 2 points. I'm not worried about the steepness of the curve...I just need a curved line to be drawn.

I've found this online but can't tell which numbers are what co-ordinate.

Can anyone help?

Thanks!

Nicky

shyam
04-14-2008, 07:21 PM
did you look at the drawArc method?

nickyfraggle
04-14-2008, 07:32 PM
Hi,

I thought that drew like a slice of a pie chart...but I've just googled it again and if you use fillArc it draws a pie chart...this one just draws the edge.

That's great...

Thanks!

nickyfraggle
04-15-2008, 12:34 AM
Also....

On a similar but slightly different note...

I am eventually trying to draw directed graphs. I want the user to be able to position the circular nodes on the screen...so I need to also draw circles...

I am drawing circles based on where the mouse clicks....but my program is drawing circles of different sizes depending on where they are drawn on the screen. I'm not sure why this is.

This is the code I have so far...


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

public class arcs2 extends java.applet.Applet {

//----------------FIELDS--------------------------
//Fields for the circle Drawing
private int mouseX, mouseY;
private int mouseXN, mouseYN;
private boolean mouseclicked = false;

//BACKROUND SETTING
public void init() {
setBackground(Color.blue);

}

//MOUSE CLICKED
public boolean mouseDown(Event e, int x, int y ) {
mouseX=x; mouseY=y;
mouseclicked = true;

/* calls paint Method to draw circles */
repaint();
return true;

}

// DRAW CIRCLE METHOD
public void paint(Graphics g) {
g.setColor(Color.green);
/* Draws circles if mouse was clicked */
if(mouseclicked) {
//DRAW CIRCLE
//take current mouse position and draw oval
mouseXN=mouseX + 20;
mouseYN=mouseY + 20;
//draw oval
g.drawOval(mouseX,mouseY,mouseXN,mouseYN);
//g.drawOval(10,50,30,30);
//g.drawArc(50,50,80,60,150,150);
/* Make mouseclicked false again.*/
mouseclicked = false;
//make variables 0 so it starts from when calculating
mouseXN=0;
mouseYN=0;
}
}
///KEEP PREVIOUS CIRCLES ON SCREEN
public void update(Graphics g) {
paint(g);
}


}

Why aren't all the circles the same size?

Thanks!!

Nicky



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum