July 31st, 2003, 02:32 PM
Drawing on a Java JFrame
I need some help with drawing text or rectangles on a Java JFrame. How do you do it?
For an applet it is easy. You set your class to extend JApplet and then use the paint(Graphics g) method. The g object can be used to draw by casting it to a Graphics2D object.
I know you need to do something like getGraphics() to the object necessary to draw, but I can never seem to get it to work.
This is for a system that lets you input some values in to an applet, you click a button, and they should be plotted in a seperate JFrame. I have it working except for the plotting part, and to do this I need to be able to draw on a JFrame.
Thanks a lot!
July 31st, 2003, 05:55 PM
As long as your class extends JFrame you are able to define a pain(Graphics g) method that can paint inside the frame. You don't need to cast it or anything.
class MyClass extends JFrame
public void paint(Graphics g)
If you can't get i working, try searching google using the keywords jframe drawrect & tutorial. Java is one of the best documented languages on the web!
August 6th, 2003, 02:49 PM
Thanks proactive. I already knew about the paint(Graphics g) method but that does not draw allow me to draw data that is entered while using the program. I did a search and came across this link:
This points in the direction of putting an Image on the frame and working with the Image. I'm going to do some more research but the example does close to what I am trying to do. Thanks!
\"When you say best friends, it means friends forever\" Brand New
\"Best friends means I pulled the trigger
Best friends means you get what you deserve\" Taking Back Sunday