aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Confusion about this reference to a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Confusion about this reference to a JFrame" Watch "Confusion about this reference to a JFrame" New topic
Author

Confusion about this reference to a JFrame

Chad McAtee
Greenhorn

Joined: Feb 23, 2011
Posts: 4


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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
Chad McAtee
Greenhorn

Joined: Feb 23, 2011
Posts: 4
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion about this reference to a JFrame
 
Similar Threads
Drawing An Image In Full-Screen
Developing Games In Java chapter 2 example not doing as i would have expected
background and foreground color is not changing in full screen window
Background color doesn't change using setBackground()
Images don't painting