This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem with the paint method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with the paint method" Watch "Problem with the paint method" New topic
Author

Problem with the paint method

Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
I have a small paint method problem, Ive just started working with it, Here is the code I have, Im trying to get a line to be drawn is all,

public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.drawLine(20,150,100,230);
}

public static void main(String[] args) {
JFrame f= new JFrame();
f.setSize(400,400);
f.setLocaton(300,300);
f.setContentPane().add(new Draw());
f.setVisible(true);
do I need to make a call to it in the main method or what? Im kinda lost and I know the answer is simple but I cant see it thanks
Jesse
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
What is the exact differnece in the methods paint and paintComponent ?
Just wondering
Thanks
Jesse
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
If you look up the paint method in the JComponent api it will explain what it does and how it relates to paintComponent.
 
Consider Paul's rocket mass heater.
 
subject: Problem with the paint method
 
Similar Threads
Rotating the Text in an Applet
AWT Background Problem
Defining the exact bottom of panel for graphic component
Funny JFrame behaviour
JPanel vs. JFrame