Introduction to Programming in Java/Swing

< Introduction to Programming in Java

About Swing Swing library is an official Java GUI toolkit released by Sun Microsystems. Swing is a lightweight component and does not use the native API's of the OS. The main characteristics of the Swing toolkit:

Swing is no longer the latest GUI toolkit for use with Java, being replaced by JavaFX. However, it will remain included in Java for the forseeable future. For more information, see the JavaFX Frequently Asked Questions.

Packages

Java Swing first programs

A basic test application for Swing is as follows:

import javax.swing.JFrame;

public class Test extends JFrame {
   public Test() {
        setSize(300, 200);
        setTitle("Test");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
   }
  public static void main(String[] args) {
       Test test = new Test();
       test.setVisible(true);
     } 
}

The constructor contains three function calls. The first two set the size and title of the window. The third statement is used to terminate the application once the window is closed; by default, the program will keep running even though the main function finishes. This is a change from non-graphical Java applications.

Display

Project: Introduction to Programming in Java
Previous: Introduction to Programming in Java/Arrays Introduction to Programming in Java/Swing Next:
This article is issued from Wikiversity - version of the Wednesday, February 17, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.