Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with the paint method

 
Jesse Walker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jesse Walker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact differnece in the methods paint and paintComponent ?
Just wondering
Thanks
Jesse
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look up the paint method in the JComponent api it will explain what it does and how it relates to paintComponent.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic