JCoster
09-13-2009, 10:20 PM
I'm new to Java programming and I'm attempting to finish off my first GUI by drawing lines between two coordinates.
I'm not too sure where to start... I've seen the public void paint(Graph g) method signature several times about but I don't understand how I could call that and add the output to an existing container.
Here is what I'm trying to do:
Container contentPane;
Graphics g = frame.getGraphics();
g.drawLine(12, 12, 400, 400);
g.setColor(Color.BLACK);
contentPane.paintComponents(g);
This is inside of a method which adds Labels and other awt objects to the container.
What happens it that when I run it, the container pops up and the line drawn flashes on for literally a split second and then disappears, but all other components stay in-tact and visible.
Any ideas?
Thanks in advance.
I'm not too sure where to start... I've seen the public void paint(Graph g) method signature several times about but I don't understand how I could call that and add the output to an existing container.
Here is what I'm trying to do:
Container contentPane;
Graphics g = frame.getGraphics();
g.drawLine(12, 12, 400, 400);
g.setColor(Color.BLACK);
contentPane.paintComponents(g);
This is inside of a method which adds Labels and other awt objects to the container.
What happens it that when I run it, the container pops up and the line drawn flashes on for literally a split second and then disappears, but all other components stay in-tact and visible.
Any ideas?
Thanks in advance.