• Post Reply Bookmark Topic Watch Topic
  • New Topic

drawing lines

 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Can anybody help out here?

Thanks,

John
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're in luck - the Javaranch CodeBarn contains an example of just such a code: http://faq.javaranch.com/java/PlotTest
 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

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.

John
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!