Top
Previous Next
Interfaces, GUIs, and Applets CS 161 - Java

SimpleGUI.java

Here is an example fo a Java application that creates a simple graphical user interface: one button displayed in a top level window with a title and borders. application
Source: examples/SimpleGUI.java



/** A very simple example of a Java GUI application
**/
 
// AWT components and Event classes used:
 
import java.awt.Button;
import java.awt.Frame;
 
public class SimpleGUI {
 
private Frame appFrame = null;
private Button doSomethingButton = null;
 
public static void main(String[] args) {
 
SimpleGUI app = new SimpleGUI();
app.run();
}
 
/** Constructor: make a frame to hold the GUI components and the
** GUI components themselves.
**/
public SimpleGUI() {
appFrame = new Frame("Simple Java GUI");
doSomethingButton = new Button("Do Nothing");
 
appFrame.add(doSomethingButton);
}
 
/** run the application
**/
public void run() {
appFrame.validate();
appFrame.setVisible(true);
}
}

Note that, other than displaying the button, this application does nothing.
Top
Previous Next
jwd