Simple Java GUI Program
Document Sample


Creating a simple GUI Application In Java Java has two packages which provide us the functionality of creating GUI application easily and these two packages are java.awt and javax.swing. These packages have everything we need to create an application. In this example I will show you how we can create a simple java GUI application. First of all we create a base of an application, where we can place components such as Button, Label and so on, and this base is created using a frame. So first we will be creating a frame using javax.swing.JFrame class. And then we will add other components to this frame. import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JLabel; public class SimpleApplication extends JFrame { private JLabel label; public SimpleApplication() { super(“Simple Java Application”); setSize(600, 400); // Measuring the center of the screen. int x = (Toolkit.getDefaultToolkit().getScreenSize().width – 600) / 2; int y = (Toolkit.getDefaultToolkit().getScreenSize().height – 400) / 2; setLocation(x, y); label = new JLabel(“Java Label”); getContentPane().add(label); } setVisible(true);
}
public static voi d main(String[] args) { new SimpleApplication(); }
Related docs
Get documents about "