I am confused about how GUI's should be implemented in Java because there are many different ways. There is this thread that already describes these proper habits: Java/Swing GUI best practices (from a code standpoint) But I am confused because when using this method Netbeans says "Overridable method call in constructor" next to functions that were called from the superclass.
I do not ask how to use GUI's or how to implement them, but I ask for the proper way of implementing them. I'm a little skeptical about this format because of that error that comes up. I have no problem running programs with this format though. At least while the programs are quite small and simple.
I get this sample code from the thread mentioned above:
public class Main {
public static void main(String[] args) {
final String text = args[0];
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final MyWindow wnd = new MyWindow(text);
wnd.setVisible(true);
}
});
}
}
public class MyWindow extends JFrame {
public MyWindow(String text) {
super("My Window");
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); //Overridable method call in constructor
addWindowListener(new WindowAdapter() { //Overridable method call in constructor
@Override
public void windowClosing(WindowEvent e) {
MyWindow.this.setVisible(false);
MyWindow.this.dispose();
}
});
final JButton btn = new JButton(text);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(MyWindow.this, "Button Pressed", "Hey", JOptionPane.INFORMATION_MESSAGE);
}
});
setLayout(new FlowLayout());
add(btn);
pack();
}
}
And this error occurs with any other method that is inherited and used in the constructor. I know this thread explains why not to do this: What's wrong with overridable method calls in constructors? So now I ask, is this still the proper style? Is this appropriate to do when implementing GUIs?
Note: Not a very experienced programmer so I hope I phrased everything correctly. I would like to learn the proper style to this all from the start.