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.
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,
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.
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)
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).
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.
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.)
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.
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.
Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.