0

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?

Ibraheem Moosa
  • 154
  • 1
  • 9
  • You can leave the initialization in main method (or in some other method called (in)directly from the main mathod) if you don't use the GUI widgets on initialization. In other case you need call it from the `run()` method inside of invokeLater statement (as it shown below). – Sergiy Medvynskyy Nov 14 '14 at 14:10
  • Possible [duplicate](http://stackoverflow.com/q/24725420/230513); see also this [limited approach](http://stackoverflow.com/a/2561540/230513). – trashgod Nov 14 '14 at 16:13

1 Answers1

0

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.

KSK
  • 149
  • 3
  • 15