Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion about this reference to a JFrame

 
Chad McAtee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What I am not understanding is how the THIS keyword is used in the screen,setFullScreen(displayMode,this);
That method requires a DisplayMode object and JFrame object to be passed to it. Im not following how THIS is referencing a JFrame object.
Also setBackground(Color.blue); setForeground(Color.white); setFont(new Font("Dialog", Font.PLAIN, 24)); in the Run method. Seems answering the first ?
would answer how setForeground ect is being applied to a JFrame that is being displayed.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your class is FullScreenTest which extends JFrame; this is referencing instance of that class, and that's why you can use it where JFrame is expected.
 
Chad McAtee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok lets me see if I understand this. You extend a class FullScreenTest extends JFrame. When the FullScreenTest class is loaded is automatically creates a JFrame object as well. Which is why in the Run() method setBackground setForegroundround and font methods.
do not create an error. So its like having an invisible object?

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chad McAtee wrote:Ok lets me see if I understand this. You extend a class FullScreenTest extends JFrame.

Actually, it's the other way around, becaus you extend JFrame class to create your own one.
An important thing to remember is that derived class object always contains a complete base class object within itself (with all inherited members of the base class - fields and methods), and that's why you can do things you asked in the first place.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic