Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Drawing on JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing on JFrame" Watch "Drawing on JFrame" New topic
Author

Drawing on JFrame

ajay smith
Greenhorn

Joined: Feb 02, 2013
Posts: 11
Simple question: how do you draw stuff on a JFrame?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2364
    
  50
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

Joined: Oct 13, 2005
Posts: 39799
    
  28
I think this discussion would fit better in our GUIs forum: moving.
ajay smith
Greenhorn

Joined: Feb 02, 2013
Posts: 11
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

Joined: Jun 13, 2009
Posts: 2215
    
    7
Read the tutorial!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Drawing on JFrame