I came across a code which calls setdefaultcloseoperation() without reference to any object. I read that methods are called with reference to object. Here is the code
public class Mainpage extends JFrame implements ActionListener{
JFrame f = new JFrame("Mainpage");
public Mainpage() {
super("Mainpage");
f.setSize(1000,6000);
f.getContentPane().setLayout(null);
f.setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE); // how is this happening?
}
I want to know how setDefaultCloseOperation(EXIT_ON_CLOSE); is working. Thanks.
Well you extended
JFrame. So in essence you are doingthis.setDefaultOperation(EXIT_ON_CLOSE).Also it doesn’t make sense that you are creating a
JFrameinside aJFrame.. unless this was an experiment of yours. Simple answer would be don’t extend JFrame, and usef.setDefaultOperation(EXIT_ON_CLOSE).