knowt logo

Swing

Swing in Java

  • What is Swing in Java? Swing is a Java package, javax.swing, provided in J2SDK. It enhances the existing AWT (Abstract Windows Toolkit) package, java.awt, offering a complete API for Java applications to operate graphical devices and create GUI (Graphical User Interfaces).

First Swing Program

  • How can you create a new window in a Swing program? Here's a simple Swing program, SwingHello.java, as an example:

import javax.swing.*;
public class SwingHello {
public static void main(String[] a) {
JFrame f = new JFrame("Hello world!");
f.setVisible(true);
}
}

Local Graphics Environment

  • What does the java.awt.GraphicsEnvironment class provide? It provides a lot of information about your local graphics device, which is your computer screen.

  • You can use the getLocalGraphicsEnvironment() method to get information about your local system.

Toolkit

  • What does the java.awt.Toolkit class provide? It can provide information about the default graphics environment, the local screen.

  • You can use the getDefaultToolkit() method to get information of the default graphics device, the local screen.

JFrame Class

  • What does the JFrame class allow you to do? The JFrame class allows you to create frames with sizes and locations; terminate program when its frame is closed; display Chinese character on frames and draw graphics on frames.

  • JFrame - This is the main window where components like labels, buttons, textfields are added to create a GUI interface.

  • JPanel - JPanel is a container that can store a group of components. It is used to create a logical grouping of components to be displayed.

  • JButton - JButton class is used to create a labeled button that has platform independent implementation.

  • JLabel - JLabel is used to display a short string or an image icon. It can also be used to display a single line of read only text, an image or both text and image.

  • JTextField - JTextField class is a component that allows editing of a single line of text.

  • JTextArea - JTextArea class is used to allow editing of multiple lines of text.

  • JCheckBox - JCheckBox is used to create a checkbox which is a small box that can either be checked or unchecked.

  • JRadioButton - JRadioButton is used to create a radio button that can be selected or deselected.

  • JComboBox - JComboBox is used to create a drop-down list that allows users to choose one value from a list.

  • JTable - JTable is used to display data in a tabular format.

  • JList - JList is used to display a list of items for selection by the user.

  • javax.swing.border - Provides classes and interfaces for drawing specialized borders around a Swing component.

  • javax.swing.colorchooser - Contains classes and interfaces used by the JColorChooser component.

  • javax.swing.event - Provides support for events fired by Swing components.

  • javax.swing.filechooser - Contains classes and interfaces used by the JFileChooser component.

  • javax.swing.plaf - Provides one interface and many abstract classes that Swing uses to provide its pluggable look and feel capabilities.

  • javax.swing.plaf.basic - Provides user interface objects built according to the Basic look and feel.

  • javax.swing.plaf.metal - Provides user interface objects built according to the Java look and feel (once codenamed Metal), which is the default look and feel.

  • javax.swing.plaf.multi - Provides user interface objects that combine two or more look and feels.

  • javax.swing.plaf.synth - Provides user interface objects for a skinnable look and feel in which all painting is delegated.

  • javax.swing.table - Provides classes and interfaces for dealing with JTable.

  • javax.swing.text - Provides classes and interfaces that deal with editable and non-editable text components.

  • javax.swing.text.html - Provides the class HTMLEditorKit and supporting classes for creating HTML text editors.

  • javax.swing.text.html.parser - Provides the default HTML parser, along with support classes.

  • javax.swing.text.rtf - Provides a class (RTFEditorKit) for creating Rich Text Format text editors.

  • javax.swing.tree - Provides classes and interfaces for dealing with JTree.

.

NS

Swing

Swing in Java

  • What is Swing in Java? Swing is a Java package, javax.swing, provided in J2SDK. It enhances the existing AWT (Abstract Windows Toolkit) package, java.awt, offering a complete API for Java applications to operate graphical devices and create GUI (Graphical User Interfaces).

First Swing Program

  • How can you create a new window in a Swing program? Here's a simple Swing program, SwingHello.java, as an example:

import javax.swing.*;
public class SwingHello {
public static void main(String[] a) {
JFrame f = new JFrame("Hello world!");
f.setVisible(true);
}
}

Local Graphics Environment

  • What does the java.awt.GraphicsEnvironment class provide? It provides a lot of information about your local graphics device, which is your computer screen.

  • You can use the getLocalGraphicsEnvironment() method to get information about your local system.

Toolkit

  • What does the java.awt.Toolkit class provide? It can provide information about the default graphics environment, the local screen.

  • You can use the getDefaultToolkit() method to get information of the default graphics device, the local screen.

JFrame Class

  • What does the JFrame class allow you to do? The JFrame class allows you to create frames with sizes and locations; terminate program when its frame is closed; display Chinese character on frames and draw graphics on frames.

  • JFrame - This is the main window where components like labels, buttons, textfields are added to create a GUI interface.

  • JPanel - JPanel is a container that can store a group of components. It is used to create a logical grouping of components to be displayed.

  • JButton - JButton class is used to create a labeled button that has platform independent implementation.

  • JLabel - JLabel is used to display a short string or an image icon. It can also be used to display a single line of read only text, an image or both text and image.

  • JTextField - JTextField class is a component that allows editing of a single line of text.

  • JTextArea - JTextArea class is used to allow editing of multiple lines of text.

  • JCheckBox - JCheckBox is used to create a checkbox which is a small box that can either be checked or unchecked.

  • JRadioButton - JRadioButton is used to create a radio button that can be selected or deselected.

  • JComboBox - JComboBox is used to create a drop-down list that allows users to choose one value from a list.

  • JTable - JTable is used to display data in a tabular format.

  • JList - JList is used to display a list of items for selection by the user.

  • javax.swing.border - Provides classes and interfaces for drawing specialized borders around a Swing component.

  • javax.swing.colorchooser - Contains classes and interfaces used by the JColorChooser component.

  • javax.swing.event - Provides support for events fired by Swing components.

  • javax.swing.filechooser - Contains classes and interfaces used by the JFileChooser component.

  • javax.swing.plaf - Provides one interface and many abstract classes that Swing uses to provide its pluggable look and feel capabilities.

  • javax.swing.plaf.basic - Provides user interface objects built according to the Basic look and feel.

  • javax.swing.plaf.metal - Provides user interface objects built according to the Java look and feel (once codenamed Metal), which is the default look and feel.

  • javax.swing.plaf.multi - Provides user interface objects that combine two or more look and feels.

  • javax.swing.plaf.synth - Provides user interface objects for a skinnable look and feel in which all painting is delegated.

  • javax.swing.table - Provides classes and interfaces for dealing with JTable.

  • javax.swing.text - Provides classes and interfaces that deal with editable and non-editable text components.

  • javax.swing.text.html - Provides the class HTMLEditorKit and supporting classes for creating HTML text editors.

  • javax.swing.text.html.parser - Provides the default HTML parser, along with support classes.

  • javax.swing.text.rtf - Provides a class (RTFEditorKit) for creating Rich Text Format text editors.

  • javax.swing.tree - Provides classes and interfaces for dealing with JTree.

.