|
RHS |
GUI Application Template
Actually there is nothing really special about an application that uses a GUI.
Simply create an application-class holding the main method as usual, then add a new file and make it a JFrame (select File - New File, then select "Java GUI Forms" and finally chose "JFrame Form").
In the application-object we simply create an object of the GUI-class and then shows it using the setVisible() method of the JFrame object.
In the following I assume that we've created a JFrame class called "ReadDataGUI" using NetBeans.
The application is named "Calculator" - the job of the application-object is simply to get the GUI-object running. We assume that all further execution is made from there.
public class Calculator {
//Constructor for the class :
public Calculator() {
//In this very simple example there is no code for the constructor!
}
//main method creates application
public static void main(String[] args) {
//Initial code (nothing in this simple application)
//Create application-object :
Calculator app = new Calculator();
//Give control to application-object by activating a method
app.runApp();
}
//A method for controlling the application
public void runApp() {
//application code goes here (simply create and show GUI):
ReadDataGUI mainWindow = new ReadDataGUI();
mainWindow.setVisible( true );
}
}
For the general template click here: Application Template