Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How do you draw in a frame?

 
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
 
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
 
    Bookmark Topic Watch Topic
  • New Topic