Where should I put my initialisation code?

94 views Asked by At

I have written a programme in java for command line. Now to convert it to gui I used Netbeans GUI Builder. The problem is I do not know where to put my initialisation codes(from the old main class). There is a main in gui but I do not think I can put there all those codes. Even then I do not think it would not be a good idea. So how can I run my initialisation codes from old main class?

1

There are 1 answers

0
KSK On

I believe you would have the beginnings of this from Netbeans, correct?

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    ... some stuff here automatically created by Netbeans (leave it).

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
               //enter initialization code here
            Main mainWindow = null;
            try {
               //enter more initialization code here
                mainWindow = new Main();
            } catch (IOException ex) {
                System.exit(1);
            }
            //enter even more initialization code here
            mainWindow.setVisible(true);
        }
    });
}

Of course, edit as you like. I would highly recommend that you DO use Netbeans automated features, especially if you're new at creating your own GUIs. Copy and paste your code from your command line app right into this automated main. Hope that helps.