Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing on JFrame

 
ajay smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple question: how do you draw stuff on a JFrame?
 
Tony Docherty
Bartender
Posts: 2957
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple question: how do you draw stuff on a JFrame?

Simple answer: you don't

What you need to do is create a component that extends JComponent or JPanel to add to your JFrame and draw on that by overriding the paintComponent() method.
I suggest you read the following tutorials: http://docs.oracle.com/javase/tutorial/uiswing/painting/ and http://docs.oracle.com/javase/tutorial/2d/

 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this discussion would fit better in our GUIs forum: moving.
 
ajay smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
Simple question: how do you draw stuff on a JFrame?


What you need to do is create a component that extends JComponent or JPanel to add to your JFrame and draw on that by overriding the paintComponent() method.



Does that mean instead of extends JFrame I do extends JPanel or extends JComponent? Very confused
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the tutorial!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic