public class MainMDI extends javax.swing.JFrame {
private static MainMDI thiz;
public MainMDI() {
initComponents();
thiz = this;
}
}
I'm creating an MDI application in swing. Class MainMDI is the main class of the application and therefore the main method resides in that class. The above code creates a static variable called thiz that points to the instance of class MainMDI when the application runs.
I'm planning to use variable thiz to access non-static (instance) members of class MainMDI from within the main method.(I cannot access non-static members from from within the main method since the main method is a static member in class MainMDI in my application).
public class MainMDI extends javax.swing.JFrame {
private static MainMDI thiz = this;
public MainMDI() {
initComponents();
}
}
But when I attempt to initialize variable thiz as in the above code, compiler says non-static variable this cannot be referenced from a static context. But I'm not referring to this in a static context here am I? Is this because variable this, being non-static, is not yet initialized when the static variable this is initialized?
Also, would it have been a better programming practice if I had not set class MainMDI as the main class and created another class with a main method in it and set that class as the main class?