I have a Swing GUI, which I build using Netbeans, which up until now used static references to communicate with other classes.
+----------------------+ | MainClass (static) | |----------------------| +------+ -DataList +-----+ | | | | static| +-+--------------+-----+ |static reference | | |reference | |new () | new () | | | | | | | | | +-+--------v----+ +--v-----------+--+ | | | | | SwingGUIClass | | ExecClasses | | | | | +--/\-----------+ +-----------------+ | Input file
(For an overview please see this question) I now want to get rid of the static references and use dependency injection.
public class SwingGUI extends javax.swing.JFrame {
private MainApp ma;
public SwingGUI(MainApp ma) {
this.ma = ma;
} [...]
One point where I struggle is, that the GUI gets started as a Thread, and as such can't have any arguments.
[...]
//still in SwingGUI.class
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SwingGUI().setVisible(true);
}
});
How can I inject dependencies while not breaking my code? Most of the questions here on SO that deal with that topic are about Guice - which at this point I don't want to use.
Thanks.