Swing: Difference between revisions

From WikiMD's Food & Medicine Encyclopedia

CSV import
Tags: mobile edit mobile web edit
 
CSV import
 
Line 1: Line 1:
changing location by moving back and forth; a square dance figure; a pair of dancers join hands and dance around a point between them; a sweeping blow or stroke; mechanical device used as a plaything to support someone swinging back and forth; a style of jazz played by big bands popular in the 1930s; flowing rhythms but less complex than later styles of jazz; a state of steady vigorous action that is characteristic of an activity; in baseball; a batter's attempt to hit a pitched ball; the act of swinging a golf club at a golf ball and (usually) hitting it; a jaunty rhythm in music; alternate dramatically between high and low values; hit or aim at with a sweeping arm movement; engage freely in promiscuous sex, often with the husband or wife of one's friends; make a big sweeping gesture or movement; play with a subtle and intuitively felt sense of rhythm; move or walk in a swinging or swaying manner; change direction with a swinging motion; turn; move in a curve or arc, usually with the intent of hitting; be a social swinger; socialize a lot: influence decisively; live in a lively, modern, and relaxed style; have a certain musical rhythm; hang freely
Swing
{{stub}}
 
{{dictionary-stub1}}
Swing is a [[Java (programming language)|Java]]-based graphical user interface (GUI) toolkit that is part of the Java Foundation Classes (JFC). It provides a set of "lightweight" (all-Java language) components that work the same on all platforms, allowing developers to create cross-platform applications with a consistent look and feel.
 
== Overview ==
Swing was developed by [[Sun Microsystems]] and is now maintained by [[Oracle Corporation]] as part of the Java Standard Edition. It was introduced in 1997 as part of the Java Development Kit (JDK) 1.2. Swing is built on top of the Abstract Window Toolkit ([[AWT]]), which is the original Java GUI toolkit.
 
Swing provides a richer set of GUI components than AWT, including advanced components like trees, tables, and text areas. It also supports pluggable look and feel, allowing applications to mimic the appearance of native applications on different platforms or to have a unique look.
 
== Features ==
 
* '''[[Lightweight Components]]''': Unlike AWT components, which are "heavyweight" and rely on the native system's GUI components, Swing components are "lightweight" and written entirely in Java.
 
* '''[[Pluggable Look and Feel]]''': Swing allows developers to change the appearance of their applications by switching between different "look and feel" themes, such as the default "Metal" look, "Nimbus", or the native look of the operating system.
 
* '''[[MVC Architecture]]''': Swing components follow the Model-View-Controller (MVC) design pattern, which separates the data (model), the user interface (view), and the interaction logic (controller).
 
* '''[[Customizable Components]]''': Developers can create custom components by extending existing Swing components or by creating new ones from scratch.
 
* '''[[Event Handling]]''': Swing uses the event delegation model for handling user interactions, which is more efficient and flexible than the event handling model used in AWT.
 
== Components ==
Swing provides a wide range of components, including:
 
* '''[[JButton]]''': A push button that can trigger an action when clicked.
* '''[[JLabel]]''': A display area for a short text string or an image.
* '''[[JTextField]]''': A single-line text input field.
* '''[[JTextArea]]''': A multi-line area to display/edit text.
* '''[[JTable]]''': A component that displays data in a two-dimensional table format.
* '''[[JTree]]''': A component that displays a hierarchical tree of data.
* '''[[JPanel]]''': A generic container for holding other components.
 
== Usage ==
To use Swing in a Java application, developers typically import the `javax.swing` package and create a class that extends `JFrame` or another top-level container. They then add components to the frame and set up event listeners to handle user interactions.
 
Example:
 
```java
import javax.swing.*;
import java.awt.event.*;
 
public class HelloWorldSwing {
    public static void main(String[] args) {
        // Create a new JFrame
        JFrame frame = new JFrame("Hello World Swing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        // Create a label
        JLabel label = new JLabel("Hello, World!");
        frame.getContentPane().add(label);
 
        // Display the window
        frame.pack();
        frame.setVisible(true);
    }
}
```
 
== Also see ==
* [[JavaFX]]
* [[Abstract Window Toolkit]]
* [[Java Development Kit]]
* [[Model-View-Controller]]
 
{{Java}}
{{Software}}
 
[[Category:Java platform]]
[[Category:Java APIs]]
[[Category:Graphical user interfaces]]

Latest revision as of 22:43, 15 December 2024

Swing

Swing is a Java-based graphical user interface (GUI) toolkit that is part of the Java Foundation Classes (JFC). It provides a set of "lightweight" (all-Java language) components that work the same on all platforms, allowing developers to create cross-platform applications with a consistent look and feel.

Overview[edit]

Swing was developed by Sun Microsystems and is now maintained by Oracle Corporation as part of the Java Standard Edition. It was introduced in 1997 as part of the Java Development Kit (JDK) 1.2. Swing is built on top of the Abstract Window Toolkit (AWT), which is the original Java GUI toolkit.

Swing provides a richer set of GUI components than AWT, including advanced components like trees, tables, and text areas. It also supports pluggable look and feel, allowing applications to mimic the appearance of native applications on different platforms or to have a unique look.

Features[edit]

  • Lightweight Components: Unlike AWT components, which are "heavyweight" and rely on the native system's GUI components, Swing components are "lightweight" and written entirely in Java.
  • Pluggable Look and Feel: Swing allows developers to change the appearance of their applications by switching between different "look and feel" themes, such as the default "Metal" look, "Nimbus", or the native look of the operating system.
  • MVC Architecture: Swing components follow the Model-View-Controller (MVC) design pattern, which separates the data (model), the user interface (view), and the interaction logic (controller).
  • Customizable Components: Developers can create custom components by extending existing Swing components or by creating new ones from scratch.
  • Event Handling: Swing uses the event delegation model for handling user interactions, which is more efficient and flexible than the event handling model used in AWT.

Components[edit]

Swing provides a wide range of components, including:

  • JButton: A push button that can trigger an action when clicked.
  • JLabel: A display area for a short text string or an image.
  • JTextField: A single-line text input field.
  • JTextArea: A multi-line area to display/edit text.
  • JTable: A component that displays data in a two-dimensional table format.
  • JTree: A component that displays a hierarchical tree of data.
  • JPanel: A generic container for holding other components.

Usage[edit]

To use Swing in a Java application, developers typically import the `javax.swing` package and create a class that extends `JFrame` or another top-level container. They then add components to the frame and set up event listeners to handle user interactions.

Example:

```java import javax.swing.*; import java.awt.event.*;

public class HelloWorldSwing {

   public static void main(String[] args) {
       // Create a new JFrame
       JFrame frame = new JFrame("Hello World Swing");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       // Create a label
       JLabel label = new JLabel("Hello, World!");
       frame.getContentPane().add(label);
       // Display the window
       frame.pack();
       frame.setVisible(true);
   }

} ```

Also see[edit]

{{{1}}} Template:Software