• Advertisement
Sign in to follow this  

Swing Drawing problem

This topic is 3827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First off I hope this is the right section to post it in. I am writing a swing application that is supposed to draw a binary tree. The problem being that while the code to do it is there and valid values are passed to do this I can't get it to draw the tree. Below is the code that is supposed to handle the drawing. While incomplete it should still draw the nodes of the tree. When the program starts up the List of the nodes is null. I then pass in a valid list of nodes from a tree I created and then pass it in to this component. It does draw stuff but never the nodes of the tree. I think it never repaints the DrawComponet object after it is initially created in the program and despite looking at examples and stuff on-line I can't fix it so that it works. If someone can help me it would be much appreciated. This is for a school assignment that is due Monday, just got one more day to fix this. I will post other parts of my code if it’s needed

public class DrawComponent extends JComponent {
	private ArrayList<BTreeNode> List;
	int Radius;
	public DrawComponent() {
		Radius = 20;
		List = null;
	}//end constructer
	public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D)g;
		if(List != null) {
			int currentx = 10;
			for(int i = 0; i < List.size(); i++) {
				g2d.drawOval(currentx, (List.get(i).getDepth() * 50), Radius, Radius);
				g2d.drawString((String)List.get(i).getElement(), currentx + 10, (List.get(i).getDepth() * 50) + 15);
				currentx += 50;
			}//end i for
		}//end (List != null) if*/
	}//end public void paint
	public void setDrawing(ArrayList<BTreeNode> list) {

		List = list;
	}//end public void setDrawing

}//end public class DrawCompnent

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement