1 Replies - 2520 Views - Last Post: 10 May 2009 - 06:56 AM Rate Topic: ***** 1 Votes

#1 System89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-September 07

Drawing Lines in a Jpanel After runtime

Post icon  Posted 10 May 2009 - 06:19 AM

Hi,

Ive been fighting with java all weekend trying to get it to draw lines after i have run my program.

The idea here is that a use insertes "node" dynamically, these nodes are in fact JRadioButtons. I can get them inserted no problem using the x and y co-ordinates of the mouse event.

My problem comes when i try draw a line from one node to the next node. Getting the x and y positions of the start and end of the line is the easy part.

My question is this: Is there any way i can re render after the program is running or is there a way to draw lines dynamically?

a section of my code may help u.

public void addLines ()
	{
		int x1 = selectedNodes[0].getX();
		int y1 = selectedNodes[0].getY();
		int x2 = selectedNodes[1].getX();
		int y2 = selectedNodes[1].getY();
		
		
			
		line = new Line2D.Double(x1, x2, y1, y2);
	   
		
		lines[lineCount] = line;
		
	  
			
	   
		g2.setColor(Color.WHITE);
		System.out.println("Add lines reached");
		/*
		g2.draw(lines[lineCount]);
		lineCount++;
		*/
	   
	}
	public void paint(Graphics g)
	{
		
		 g2 = (Graphics2D) g;
	   

	  
	}
   


Please help, its rather urgent at this time. I appreciate all the help u guys can give me...
Thank u!

Is This A Good Question/Topic? 0
  • +

Replies To: Drawing Lines in a Jpanel After runtime

#2 System89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-September 07

Re: Drawing Lines in a Jpanel After runtime

Posted 10 May 2009 - 06:56 AM

Solved It myself.

returned the graphics context of the JPanel it was in.

Using JPanelName.getGraphics ();

assinged that to g2 of type Grpahics2D, just had to cast it which netbeans will sort out.

Now it draws perfectly from node to node!

:)

This post has been edited by System89: 10 May 2009 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1