• Post Reply Bookmark Topic Watch Topic
  • New Topic

The paint() method.

 
Utsav Harsh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner for AWT and APPLETs. I tried the following code in eclipse:


Why am i getting this output:
This is my first applet and I am in init(). After that I jumped onto start(). At last I am in paint(). At last I am in paint().

At last I am in paint() is printed twice...
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe it's the line


that trigger the paint() method again hence the "At last I am in paint()" message printed twice.

And welcome to the Ranch
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

In future, while posting code, please UseCodeTags I have added them this time for you. As you can see, the tags make the code much more easier to read and understand.

Utsav Harsh wrote:Why am i getting this output:
This is my first applet and I am in init(). After that I jumped onto start(). At last I am in paint(). At last I am in paint().

That's because these three methods are invoked in a specific sequence. More on it here
http://docs.oracle.com/javase/tutorial/deployment/applet/lifeCycle.html

Utsav Harsh wrote:At last I am in paint() is printed twice...

The paint() is invoked by the JVM when the UI (or part of it) needs to be (re)painted. e.g. When you drag another window over your applet.

On a side note, you should be moving over to Swing instead of AWT. Swing has direct replacements for almost all the AWT components
e.g.
Applet (AWT) -> JApplet (Swing)
Frame -> JFrame
Button -> JButton

Also, the paint() is replaced with paintComponent() in swing. More on custom painting here http://docs.oracle.com/javase/tutorial/uiswing/painting/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!