public class MyFrame extends JFrame {
MyFrame() {
MyPanel panel = new MyPanel();
this.add(panel);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(false);
this.pack();
this.setVisible(true);
}
} ```
So I'm looking at this right now and a little bit confused. What I knew about "this" was the fact that it can be used to not confuse java when you have a variable with the same name in the field and again in another method. In this case why are we allowed to use this without any object?
#what does the keyword this do exactly?
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @gloomy rain! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
You do have an object. You're in a constructor
a constructor is just a special kind of method, this refers to the newly created instance of MyFrame, in your case
"special kind of object?" A constructor is something that runs on a partially constructed object, that finishes its construction per the spec of the current class
brain turned off, special kind of method*