Say I have 4 int values (5, 10, 7, 18). How can I use them in some type of coordinate system and draw a line? I've looked at the Point2D and Line2D, but can find no examples for them. The next part of the question is onto "what medium" can I "draw" the line?
Eventually, whatever I draw this "line" on I need to put on a JPanel.
Ok, how/where is paintComponent called? I see the class extends JPanel and down in main a JFrame is declared with a JPanel attached. Nowhere do I see anything that calls paintComponent().
Can you try to explain this? As you may have guessed, I've not done much/any graphics programming before.
posted 11 years ago
paintComponent is the method that gets called automagically by the JVM for all Swing components that need to be drawn. In other words, this is where you put the code that draws whatever you want drawn, and it will be called whenever appropriate. E.g. during the initial drawing, or whenever a part of it was obscured by another window, or if the application gets switched to the foreground.
If you're serious about getting into Swing, you might want to work through the Swing Tutorial. The section on Performing Custom Painting is particularly relevant here.
I'll move this discussion to the AWT/Swing/GUI forum.