Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Introduction and Importance of Java Swings

The article provides you with the details on making use of Swing Components and explains some of the useful and most commonly used Swing Components.

What do you mean by Swings in java?

  • An element of The JFC
  • Swing Java consists of:
    • Look and feel
    • Ease of access
    • Java 2D
    • Drag and Drop, etc
  • Compiling & executing programs
  • ‘javac <program.java>’ && ‘java <program>’

  • If you do not clearly add a GUI constituent to a container, the GUI part will not be put on view when the container comes into view on the screen.

Swing, wing documentation to the AWT, comprise of novel and better mechanism that improve the look and functionality of GUIs. Swing can be deployed to come up with an altogether a Standalone swing Graphical User Interface software or applications and also the Servlets and Applets. It makes use of a model/view design structural design. AWT is not as portable and flexible as Swings are.

Swing Representation/outlook Plan:

Component object and the UI one are being used to put into the practice the “view part” of the MV plan or design. On the other hand, Model object and Change listener help is taken to implement the “model view” of the MV design.

Built on the platform of AWT, Swing is basically written in Java language. The support of an AWT’s lightweight component assistance is taken so as to come up with the Swings.

Overall, the design or the architecture of the components or elements of Swings make it much simpler to come up with both the outlook/appearance and behaviour as well. The mixture of AWT and Swing elements or constituents permits it to provide Swing support to the current programs based on AWT.

Example includes, swing mechanism such as JSlider, JButton and JCheckbox could be deployed in the equivalent code with pattern AWT tags, text fields and scrollbars. You could subclass the active or current Swing UI, model, or change listener classes with no need to have rediscovered the whole functioning. Swing also has the skill to put back these matter on-the-tracks.

  • 100% Java performance of machinery
  • Pluggable Appear & sense
  • Lightweight mechanism and procedures
  • Bring into play MVC design
  • Model corresponds to the data
    Outlook as a visual demonstration of the data
    Controller takes input and decode it to alterations in data

  • Three components
  • Constituent set (subclasses of JComponent)
    Sustain classes
    Interfaces

Classes that symbolize Graphical User Interface elements in Swings have names initiating with the alphabet J. Few of the illustrations include JButton, JLabel, and JSlider. Overall, 250 new classes and 75 interfaces in Swing are there and even more than that and this is double as many as AWT contains.

Ladder for java Swing Class

The class know by the name of JComponent, when moved down straight from Container, is the core class for majority of Swing’s user boundary constituents.

Graphical User Interface

Figure 1: Graphical User Interface

Swing consists of elements or constituents that a developer will be making use of to come up with a Graphical User Interface. Let us take a look at some of the most commonly used elements or components of the Swing. The programming know-how of AWT is not at all required to equip with these swing programs.

Illustrations displaying Java Swings

The conventional and the most famous Hello World program is our example for Java Swing as well.

The overall objective to bring this Hello World Program to you all is to teach on how a java program can be created, and then how to compile it and then execute or run the same.

Any Editor such as Text pad/Edit plus or the favourite of all, an IDE like Eclipse can be made use of to come up with a java source code.

Listing 1: Full source code

import javax.swing.JFrame;
import javax.swing.JLabel;

//import declaration
//Verify if the dialog window turns off of its own. Else, introduce appropriate code
public class HelloWorldFrame extends JFrame {

	public static void main(String args[]) {
		new HelloWorldFrame();
	}
	HelloWorldFrame() {
		JLabel jlbHelloWorld = new JLabel("Hello World");
		add(jlbHelloWorld);
		this.setSize(100, 100);
		// pack();
		setVisible(true);
	}
}

Output

Output Hello World

Figure 2: Output Hello World

Java Swing Elements

  • JPanel- It is a Swing’s edition of the AWT class Panel and makes use of the exactly same default plan and the flow layout.
  • Jframe - This is a Swing’s description of Frame and is moved down straight from that class. The elements supported to the frame are known as the its constituents and managed by contentPane. Adding an element to a JFrame requires the use of a contentPane.
  • JInternalFrame- This is restricted to a noticeable region of a container it is located in.
  • JWindow - Known as the Swing’s edition of Window and is moved down directly from that class, it deploys BorderLayout.
  • JDialog - this element is nothing but the Swing’s part of the Dialog and is descended directly from that class. This also makes use of the BorderLayout by default. JDialog comprise of the rootPane ladder or hierarchy and also a contentPane, much on the similar lines of the JFrame and JWindow. It permits the layered as well the panes of glass. Each of the dialogs is modal thereby referring to the existing thread that is jammed till the time interaction with the user has taken place completely.
  • JLabel- Talking about the JLabel now, this is used to come up with the text labels. AbstractButton, the abstract provides a sort of platform to a family of elements consisting of buttons, classes as well as the Jbutton.
  • JTextField- the elements I popular or rather made use to permit the modification of a single line of text. Some of the new attributes compromise of the skill to prove the text left, right, center etc.
  • JPasswordField- Thinking to suppress the input display? Then this is the right element for you to do so. Each of the data or the character entered can be be restored by an echo character. This actually permits to enter the secret or confidential passwords, example includes the echo character as asterisk, *.
  • JTextArea- The component is used to edit multiple text lines. It can be used in parallel with JScrollPane so as to accomplish scrolling which according to the need can be requested to have or even disallow the vertical or horizontal scrollbar.


I am a software developer from India with hands on experience on java, html for over 5 years.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login