• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How do you draw in a frame?

 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Danger, 10,000 volts, very electic .... tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic