Java Tutorial

by Dinesh Thakur Category: Swing

As a group of radio buttons, a drop-down list is a form of forcing the user to select only one element of a group of possibilities. However, it is a more compact way to do this, and is easier to change the elements of the list without surprising the user.

 
by Dinesh Thakur Category: Swing

The radiobutton component is a two state button which can either be selected or not selected, similar to a checkbox component. However, unlike checkboxes, the radiobuttons are associated with a group and only one radiobutton in a group can be selected. When the radiobutton in the group is selected, any other previously selected radiobutton in the group is deselected. The JRadioButton class is a subclass of JToggleButton which is further a subclass of AbstractButton.

 
by Dinesh Thakur Category: Swing

A checkbox component in Swing is similar to checkbox component in AWT. A check box is a control that consists of a combination of a small box and a label. The label provides the description of the box with which it is associated. It is a two-state control having states true (checked) and false (unchecked). The state of a checkbox can be changed by clicking on it. A checkbox is an object of JCheckBox class.

 
by Dinesh Thakur Category: Swing

A Textfield is a component used for displaying, inputting and editing a single line of plain text. We can create text field by creating an instance of JTextField class. The JTextComponent is a superclass of JTextField that provides common set of methods used by JTextfield.

 
by Dinesh Thakur Category: Swing

The Buttons component in Swing is similar to the Button component in AWT except that it can contain text, image or both. It can be created by instantiating the JButton class. The JButton class is a subclass of AbstractButton class.

To the text on the face of an object is called JButton button label. Having more than one JButton object with the same tag makes the JButton objects are ambiguous for the user (each button label must be unique).

 
by Dinesh Thakur Category: Swing

The PasswordField is a special kind of textfield. It is a single line textfield used for accepting passwords without displaying the characters typed in. Each typed character is represented by an echo character typically an astriek (*). To create a PasswordField component, instantiate the JpasswordField class.

 
by Dinesh Thakur Category: Swing

The TextArea component in swing is similar to the TextArea component in AWT as it allows to display and edit multiple lines of plaintext. But unlike TextArea component in AWT, if all the text cannot be displayed in the available space in the component, scrollbars are not automatically added. In order to add scrollbars, you must insert it into a ScrollPane.

 
by Dinesh Thakur Category: Swing

JLabel component in swing is similar to label in AWT except that it may contain uneditable text, an image or both. We can create label by creating an instance of JLabel class.

 
by Dinesh Thakur Category: Swing

Another way of creating an application window is by defining a new class that extends the JFrame class. The new class will inherit fields and methods from the JFrame class. This technique is a preferred style for creating GUI applications.

 
by Dinesh Thakur Category: Swing

In order to add a component to a container, first create an instance of the desired component and then call the add () method of the Container class to add it to a window. The add() method has many forms and one of these is,

 
by Dinesh Thakur Category: Swing

Every program with a Swing GUI must contain atleast one top level swing container and JFrame is the most commonly used top level container for creating GUI applications.

 
by Dinesh Thakur Category: Swing

In this Example, JFrame class is a predefined class present in swing package. This class is used to generate a frame and takes string argument. getTooZkit () method is a predefined method of Toolkit class. It returns the system's default Toolkit object. The default Toolkit is identified by the System property awt.toolkit.

 
by Dinesh Thakur Category: Swing

In this Example, Calendar class is an abstract class present in java.util package. getInstance method is a static method of Calendar class. This method is used to create the object of Calendar class. Return type of this method is Calendar class object. Syntax-public static Calendar getInstance (). get method is a predefined method of Calendar class. It is used to return the value of a given calendar field. Return type of this method is int type. Syntax-public int get (int)



 
by Dinesh Thakur Category: Swing

JOptionPane Class is present in javax.swing package. This class is used to display simple dialog boxes to get the text input From the user. showInputDialog method is a static method of JOptionPane class. This method uses single parameter that specifies the prompting message that is displayed in the dialog box. In this program message is- "Enter the Number for Right Angle Trangle Height?" This method returns string value. Syntax- public static String showInputDialog (String s).

 
by Dinesh Thakur Category: Swing

Java class named JOptionPane that produce dialog boxes. A dialog box is a GUI object in which you can place messages that you want to display on the screen. The showMessageDialog() method that is part of the JOptionPane class. The showMessageDialog() method is followed by a set of parentheses. The showMessageDialog() are two arguments. The first argument is null. its means the message box should be shown in the center of the screen. After the comma, second argument is the string that should be output.

 
by Dinesh Thakur Category: Swing

The basic component that require whenever we implement a visual interface to rid Swing is the JFrame (top-level container) class. This class encapsulates a classic window any operating system with graphical environment (Windows, OS X, Linux etc.)



 
by Dinesh Thakur Category: Swing

Progress indicators or progress bars are the new controls that give the users some indications of the progress of an operation. When we call JProgressBar, we can set the maximum and minimum value for the progress bar.

 
by Dinesh Thakur Category: Swing

Lists are supported in Swings by the JList class. It is a very popular control as it allows the user to present a list of items in an easier and efficient manner. It also allows hiding the long list of items by making the lists scrollable. JList has been inherited from a long list of classes.

 
by Dinesh Thakur Category: Java Methods

To create a class variable or method, include the word static in front of the method's name. The modifier static typically comes after any protection modifiers. Given below is an example that illustrates how a class variable may be created in a program.

 


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.