Question:

Java Programming:the difference between public void paint(Graphics g) and public static void drawMan..?

by  |  earlier

0 LIKES UnLike

the difference between public void paint(Graphics g) and public static void drawMan(int xpos, int ypos, Graphics g) ? Please explain.

 Tags:

   Report

1 ANSWERS


  1. Not exactly sure what you're asking, but the main difference I see is that the first is an instance method and the second is static. You haven't provided info on the classes that these methods go with, but in the first case you need an actual instance of that class (say a JPanel), and then you call the paint method, passing in a graphics object like myPanel.paint(g). However, in the second one, you don't need an instance of the class since the method is static. So you do this by calling the class name and the method. In this case, it might be used to put something into the graphics object. I don't know what "drawMan" means, but take literally, one might expect this method to take the Graphics object passed in and draw a stick figure man at the point (xpos,ypos). It would not be drawing to a Panel or Canvas because there's no instance to draw on - so I'm guessing the only object to affect is the Graphics one passed in.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions