article

Friday, June 10, 2016

Java Swing


Java Swing

Swing is the principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java programs. It is completely written in Java.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.tutorial101;
 
import java.awt.EventQueue;
import javax.swing.JFrame;
 
public class SimpleEx extends JFrame {
 
    public SimpleEx() {
 
        initUI();
    }
 
    private void initUI() {
         
        setTitle("Simple example"); //window title
        setSize(300, 200); //size window
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
 
    public static void main(String[] args) {
 
        EventQueue.invokeLater(new Runnable() { //This method will close the window if we click on the close button of the titlebar
         
            @Override
            public void run() {
                SimpleEx ex = new SimpleEx();
                ex.setVisible(true);
            }
        });
    }
}

Related Post