Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you draw in a frame?  RSS feed

 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I would like to know, how you draw in a JFrame (or something similar) as you draw in an Applet?
This might seem like a stupid question - but I can't find any ressources. The problem is how to draw, say a small image or a circle on the frame and make it move.
Thanks in advance!
/Svend Rost
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
U need to override the conatiner's paint() method and call repaint() in the constructor of the JFrame.
e.g.

as for the animation, u need to use a thread and change the color or position of the x,y coordinates dynamically.
Shashi
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer
Oh! I can do that ?
So basicly, I can use alot of the code from applets in my JFrames ?
/Svend Rost
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
U cannot use any of the Applet's methods in JFrame except for paint() method!!
paint(Graphics g) is in fact the class Container's paint() method.
Whenever u need to do some sort of drawing on the container, u use this method.
Regards,
Shashi
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!