Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts

    drawing a curved line between 2 points

    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

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    did you look at the drawArc method?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    nickyfraggle (04-14-2008)

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    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!

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    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...

    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •