Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Trying to understand pubic void paint(Graphics g)

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have read from the book , that the methodis automatically called by the JVM if we override it after extending it from Frame class...

Is this true? Because i cannot find any such mention in the Oracle Docs that the function is called by JVM at runtime..

For Example , i have written a very simple application where i have not called paint() method by any object , still i can see , that it was called....

So please help me , on this

 
Marshal
Posts: 68917
275
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using AWT display components? There are links in the paint() method documentation; have you read them?
 
Marshal
Posts: 25452
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gourav Das wrote:Is this true? Because i cannot find any such mention in the Oracle Docs that the function is called by JVM at runtime.



The documentation is there to tell you what the methods do. It's not there to explain how they are used by other code. However if you read any good tutorial about Swing it will certainly tell you that.

Have you read any tutorials? Swing is really really hard to learn by trying random things to see what works.
 
Campbell Ritchie
Marshal
Posts: 68917
275
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method's documentation and the link therein both say when that method is called. But who is interested in an AWT method any more?
 
Gourav Das
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Gourav Das wrote:Is this true? Because i cannot find any such mention in the Oracle Docs that the function is called by JVM at runtime.



The documentation is there to tell you what the methods do. It's not there to explain how they are used by other code. However if you read any good tutorial about Swing it will certainly tell you that.

Have you read any tutorials? Swing is really really hard to learn by trying random things to see what works.



can you please suggest me a good swing tutorial? All i am doing is just learning from the Docs and trying to find out what each method does/....
 
Gourav Das
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The method's documentation and the link therein both say when that method is called. But who is interested in an AWT method any more?



i know awt is old and not used , but its quite fun actually to learn it ,by learning it i am able to understand how JFrame inherits Frame and what Frame actually does... it helps me clearly see the big picture.. otherwise a beginner like me is always confused
 
Rancher
Posts: 3158
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing is built on top of AWT so Swing does use may AWT glasses.

However, there is no need to use AWT components. All the AWT components have been replaced by Swing components, so use the Swing components.

While learning to use Swing components you will also learn basic AWT concepts.

can you please suggest me a good swing tutorial?



See: Creating a GUI with JFC / Swing
 
Rancher
Posts: 886
22
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
paint, and paintcomponent are called by the system when a portion of the screen or object needs to be refreshed, paintcomponent is called by the system when a repaint() is called in your Swing code--the repaint() only requests a paintcomponent be called, but is not a hard schedule as the System can still do whatever it needs to do including ignore the repaint call, but that is a fairly drastic case.

paint is the bottom most drawing routine of the call chain for refreshing the graphics of an object, if I understand correctly, as such you "should only" call paint when essential to do so--like almost never except in AWT.

Having said that: if you are running a JFrame, then paint is the method that is called when a repaint() schedules a request.  Most, and good practice, usually use a JPanel to house elements you need in your GUI, and thereby avoid the need to be messing with paint in the JFrame by pretty much mandating the override of paintcomponent methods of your classes you wish to modify in your GUI.

There are excellent tutorials on 2D graphics on the Oracle site, I suggest looking them over.  They will deal better and probably more accurately with the subject than my memory does ;)

Les

BTW: been so long since I'd seen an AWT question I totally missed you were working with AWT--stop it, and work with SWING.
 
Pay attention! Tiny ad!
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic