Turn Desktop View Off
by Dinesh Thakur

A timer is an object of Timer class which is the subclass of Object class present in java.lang package. A timer fires one or more action events after regular interval of time (in milliseconds) called delay.



 
by Dinesh Thakur

The JWindow class is used to create a window which does not have any toolbar, border or window management buttons. This type of window is usually used to display messages like welcome messages, Copyright information, etc. The commonly used of constructor of JWindow class is as follows.



 
by Dinesh Thakur

The grid bag layout manager is the most advanced and yet easy to use layout manager. A GridBagLayout arranges the component in a grid of rows and columns. It allows different sized components to span multiple rows or columns. Also, each row in the grid can have different number of columns. Grid bag layout specifies a grid of cells with the container determines the component's size and then positions each component in one or more cell accordingly.

 
by Dinesh Thakur

A layered pane is a Swing container which is used to hold the various components using the concept of layers. The components present in the upper layer overlaps the components present in the lower layer. The layered pane is created using the JLayeredPane class. the only constructor of this class is JLayeredPane ().

 
by Dinesh Thakur

Scroll bars are horizontally or vertically oriented bars which allow the user to select items between a specified minimum and maximum values. Each end of the scroll bar has an arrow which can be clicked to change the current value of the scroll bar. The slider box indicates the current value of the scroll bar which can be dragged by the user to a new position. Scrollbar is an object of ScrollBar class.

 
by Dinesh Thakur

Swing component is an independent control, such as button, label, text field, etc. They need. a container to display themselves. Swing components are derived from JComponent class. JComponent provides the functionality common for all components. JComponent inherits the AWT class Container and Component. Thus, a Swing component and AWT component are compatible with each other.

 
by Dinesh Thakur

Swing, a part of Java Federation Classes (JFC) is the next generation GUI toolkit that allows us to develop large scale enterprise applications in Java. It is a set of classes which provides many powerful and flexible components for creating graphical user interface. Earlier, the concept of Swing did not exist in Java and the user interfaces were built by using the Java's original GUI system, AWT. Because of the limitations of the AWT, Swing was introduced in 1997 by the Sun Microsystems. It provides new and improved components that enhance the look and functionality of GUIs.



 
by Dinesh Thakur

• The (Model View Controller) MVC design pattern separates a software component into three distinct pieces: a view, a model  and a controller.

• The model stores the content. It manages the state and conducts all transformations on that state. The MVC model has no specific knowledge of either its controllers or its views. The Link is maintain by system between model and views and notifies the views when the state change occurs. For example - For the button component model will hold the information about the state of button such as whether the button is pushed or not.

• The view displays the contents. It manages the visual display of the state represented by the model. Thus  model view can be represented graphically to the user. For example - For example: For the button component the color, the size of the button will be decided by the view.

                                    MVC Design Pattern

 

• The controller is for managing the user interaction with the model. It is basically for handling the user input. The controller takes care of mouse and keyboard events. For example - For the button component the reaction of events on the button press will be decided by the controller.

• The MVC architecture of swing specifies how these three objects(Model, View and Controller) interact.

• For the text field the model is nothing but the contents of the text field. The model must implement the method to change the contents and to discover the contents. For example text model had methods to add to remove the characters. One important thing to note is that the model is completely non visual.

• For a single model there can be more than one views. Each view can show different aspect of the content. For example: A particular web page can be viewed in its WYSIWYC(What-You-See-Is-What-You-Get)) form or in the raw tagged form. But there are some components like button for which it is not possible to have multiple views for the same model.

• The controller handles the user-input events such as mouse clicks and keyboard strokes. On receiving the events the controller decides whether to translate it into corresponding model or in views.

• If user presses the button then the controller calls the event handling methods in order to handle the button press. The controller tells the view to update itself and to display the desired result. For displaying the desired result the view reads the content from the model. Thus model-view and controller works together in order to accomplish the certain task.



 
by Dinesh Thakur

Java graphics programming is possible using AWT i.e. Abstract Window Toolkit and swing components. Swing is a set of classes. These classes provide the components that are more powerful and flexible than AWT.



 
by Dinesh Thakur

Using the JPopupMenu class, context-sensitive pop-up menus can be created, which are provided in most of today's computer applications. These menus are used to provide options specific to the component for which the pop-up trigger event was generated. The pop-up trigger events occur when the right mouse button is either pressed or released. Program demonstrates how such a pop-up menu can be created.



 
by Dinesh Thakur

Some of the packages of swing components that are used most are the following:

 
by Dinesh Thakur

A dialog box ("dialog" for short) is any box, or window, on the screen that you have a dialog with. You can decide to pop up some dialog boxes j to enter information in, or make choices about how a program works. "Other dialogs appear automatically to give you simple messages (such as "Your disk is full") and ask you what you want to do about it.



 
 
by Dinesh Thakur

Sometimes a situation may arise when there are lots of components that cannot be accommodated in a single screen. In that case, tabbed pane is used to create tabs where each tab contains group of related components. When a particular tab is clicked, the components of that tab are displayed in the forefront. Tabbed pane is very common feature of GUI interfaces. It is commonly used in dialog boxes containing lots of commands. A tabbed pane is an object of JTabbedPane class.

 
by Dinesh Thakur

A confirmation dialog box is meant for asking a confirmation question and allows the user to give a yes/no/cancel response. It is created by using the static method showConfirmDialog() of JOptionPane. The general form of showConfirmDialog()method is

 
by Dinesh Thakur

An internal frame is similar to a regular frame which can be displayed within another window. It is a lightweight component which can be resized, closed, maximized or minimized depending upon the properties being set. It can also hold a title and a menu bar. An internal frame is an object of JinternalFrame class.

 
by Dinesh Thakur

The following example is a simple demonstration of cut, copy, and paste String data type with a JTextArea. One thing you will notice is that the keyboard sequences normally used to cut, copy and paste also work. But if you look at any JTextField or JTextArea in any other program, you will find that these also support keyboard sequences clipboard automatically. this example simply adds programmatic control of the clipboard, and You can use these techniques if you want to capture text from the clipboard into something else than a JTextComponent.



 
by Dinesh Thakur

A slider allows the user to enter a point moving data back and forth, which is intuitive in some situations (volume control, for example). a progress bar displays data in a relative form of "full" to "empty" so the user gets a perspective.

 
by Dinesh Thakur

Any component that can take text can also make HTML text , which will be formatted according to HTML rules. this means you can easily add text decorated in a Swing component.

 
by Dinesh Thakur

The java.awt.event.TextListener interface allows to react to changes the text contained in components of type TextField and TextArea. The addTextListener () method enables a text component to generate user events. the method TextValueChanged () receives events.



 
by Dinesh Thakur

JSpinner: Selects a value from a range of possible options to Like the drop-down lists, but show no such list. values changed by pressing the scroll buttons. You can also enter a  value directly.

 
by Dinesh Thakur

Slider in Swing is similar to scroll bar which allows the user to select a numeric value from a specified range of integer values. It has a knob which can slide on a range of values and can be used to select a particular value. For example, sliders are used in media players, to adjust volume, to set channel frequency, etc. Like scroll bars, they can also be horizontal or vertical. A slider is an object of class JSlider which is direct subclass of JComponent. The class JSlider also implements the interface SwingConstants.

 
by Dinesh Thakur

The java.awt.event.KeyListener interface, present in virtually all AWT component is used to respond to events triggered by  keystrokes when the focus is on the component. Allows the preprocessing  the input provided by the user and other sophisticated actions. its  interface requires the keyPressed, keyReleased method are implemented and  keyTyped. The associated event, java.awt.event.KeyEvent has the following methods  of particular interest are listed below:



 
by Dinesh Thakur

The java.awt.event.ItemListener interface is responsible for processing events  java.awt.event.ItemEvent action generated by the activation of checkboxes (Checkbox), option buttons (CheckboxGroup) and items in menus option type  (CheckboxMenuItem). Its implementation requires the inclusion of the method  itemStateChanged these classes.



 
by Dinesh Thakur

The java.awt.event.ActionListener interface is responsible for processing events java.awt.event.ActionEvent action generated by the drive buttons (Button), selection items (MenuItem) in suspended (drop-down) or independent menus (popup) at Pressing the "Enter" in inboxes (TextField) and double-click boxes list (List). Its implementation requires the inclusion of the actionPerformed method in these classes.



 
by Dinesh Thakur

JOptionPane is a subclass of JComponent which includes static methods for creating and customizing modal dialog boxes using a simple code. Previously, you have seen that creating a dialog box using JDialog makes the code cumbersome. So JOptionPane is used instead of JDialog to minimize the complexity of the code. JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user.



 
by Dinesh Thakur

The option dialog box provides the feature of all the above three discussed dialog boxes. It is created by using the static method showOptionDialog () of JOptionPane. The general form of showOptionDialog () method is

 
by Dinesh Thakur

Using a JTree is as simple as saying:

add(new JTree( new Object[] {"One", "Two", "Three"}));
This displays a primitive tree. The API is huge tree without But, certainly one of the longest of Swing. It seems that you can do everything with trees, but the most sophisticated tasks may require quite a bit of research and experimentation.

 
by Dinesh Thakur

JTree: One of the most interesting new classes that Swing offers is the JTree class. this class implements a tree-like structure that can be used to display data hierarchical. TreeNode interface defines the methods that must be implemented nodes a JTree object. The class provides a DefaulMutableTreeNode default implementation of the TreeNode interface. The trees are created constructing the TreeNode interface objects and then add them all together (through of ()) method add. When all TreeNode objects have been assembled, the object Resulting TreeNode to JTree constructor is passed.

 
by Dinesh Thakur

JToolTip: Consists of a help tab that arises after one second on the position pointed to by the cursor. Normally it is not necessary to use JToolTip class directly, can be set to any component window by: e.setToolTipText ("This is the label").

 
by Dinesh Thakur

JToolBar: A container that allows you to group other components, usually buttons with icons in a row or column. Bars tools are unique in that the user can place them in different configurations on the main frame.

 
by Dinesh Thakur

The ButtonGroup class allows to manage a set of buttons ensuring that only one button in the group will selected. To use the ButtonGroup class, simply instantiate an object and add buttons (objects that inherit from the class AbstractButton) through the add () method. It is preferable to use objects JToggleButton class or one of its subclasses because they are able to manage their states.

 
by Dinesh Thakur

Swing provides a variant of push button called toggle button which has two states: pushed and released. When toggle button is pressed for the first time, it remains pressed and it is released only when it is pressed for the second time. This button toggles between pushed and released state. Toggle button is an object of JToggleButton class.

 
 
by Dinesh Thakur

Textfield control creates a single-line text area. The text field allows the user to enter and edit the text using cut, copy and paste keys, arrow keys and mouse selections. It is an object of JTextField class which is a subclass of JTextcomponent.

 
by Dinesh Thakur

The JTextField is a text field of a single line. Class inherits from the javax.swing.text.JTextComponent. Its methods include:

 
by Dinesh Thakur

The JTable controls how the data is displayed, but the TableModel (table model) controls the data itself. So to create a JTable will typically create a TableModel first. It can be implemented TableModel interface completely, but is usually simpler to inherit the kind of help AbtractTableModel:

 
by Dinesh Thakur

The JTable class is another Swing component that has no equivalent in AWT. JTable provides a very flexible possibility to create and display tables. Lets build tables from arrays or vectors of objects or from objects that implement the TableModel interface.

 
by Dinesh Thakur

JTabbedPane : Set multiple tabbed sheets, which may contain other components. The user can select the sheet you want to see by tabs.

With the JTabbedPane class, we can have several components (usually objects JPanel) sharing the same space. The user can choose which component see selecting the tab of the desired component.

 
by Dinesh Thakur

A split pane is a lightweight container that allows you to arrange two components (only two) side by side horizontally or vertically in a single pane. The display areas of both the components can also be adjusted at the runtime by the user. A split pane is an object of JSplitPane class.

 
 
by Dinesh Thakur
 
by Dinesh Thakur
 
by Dinesh Thakur

Progress bar is a user friendly control which is used to indicate the current status of some time consuming tasks such as software installation etc. It indicates the progress of a task by showing the percentage of completion using a color bar. The progress bar can be of two types namely, horizontal progress bar and vertical progress bar. In horizontal progress bar, the progress is indicated by filling the bar from left to right and in vertical progress bar, the progress is indicated by filling the bar from top to bottom. ·

 
by Dinesh Thakur

JProgressBar: Displays the percentage of the total has a task to perform been completed. JProgressBar lack equivalents in the AWT. JprogressBar classes support horizontal and vertical orientations. The class is used JProgressBar  typically to show the progress of a task, such as loading an image.

 
 
 
by Dinesh Thakur

Overlay is a process of laying one component over another one. You can use Graphics2d to over layout one textfield component to another textfield.

 
by Dinesh Thakur

List displays a list of items. It allows the user to make multiple selections from the given list of items. The list component is added in a scroll pane, so that the long list of items is scrollable. A list is an object of JList class.

 
 
by Dinesh Thakur

There are several kinds of buttons in computer applications, buttons that you click on with the mouse pointer or that you activate with a key stroke. Buttons provide a way to tell the computer what to do. The buttons with the little round dots are called radio buttons, and they always come in groups of two or more. A set of radio buttons is a visual clue that you only have a choice of one of those options. Choosing another button automatically turns off the button that was currently selected, just like pressing a button on your car radio switches you from one station to the next.



 
by Dinesh Thakur

We understand all upper menu structure of a graphical application that allows us to display a list of operations that in turn can contain other lists of operations. The basic structure consists of a menu JMenuBar (the top bar) from which dangle (JMenu) menus that we add elements (JMenuItem) that can be JCheckBoxMenuItem, and even JRadioButtonMenuItem JMenu. Consider now the methods of each of these classes:

 
by Dinesh Thakur

JListThe JList is a list on which we can view and select more than one item simultaneously. In case there are more items than can be simultaneously displayed due to the size of the list, a vertical scroll bar appears. Relevant methods:

 
by Dinesh Thakur

A layered pane is a Swing container which is used to hold the various components using the concept of layers. The components present in the upper layer overlaps the components present in the lower layer. The layered pane is created using the JLayeredPane class. the only constructor of this class is JLayeredPane ().

 
by Dinesh Thakur

A label is a simple control which is used to display text (non-editable) on the window. Since it does not possess any user interactive feature, it is considered as a passive control. A label is an object of

 
by Dinesh Thakur

Many of today's applications provide a facility wherein the users can open multiple documents without having to close current document. They can then switch between the documents and update them. For this purpose, applications use the multiple-document interface to manage these multiple open documents being processed in parallel (This is a main window, often called parent window, which contains several other windows, which also called child window.) JDesktopPane and JlnternalFrame classes of the Swing package help to create these multiple-document interfaces.

 
 
by Dinesh Thakur

Some operating systems have some special dialog boxes including selection to handle things like fonts, colors, printers and the like. Virtually all operating systems support the opening and storage of files, however, and thus the Java JFileChooser encapsulates this for easy use. JFileChooser, Opens a dialog box to ask for a filename.



 
 
 
by Dinesh Thakur

An input dialog box is used to accept data from the user. It appears with a component like text field, combo box or list which lets the user to input the data. It is created by using the static method

 
by Dinesh Thakur

showMessageDialog Displays a modal dialog with a button labeled "OK". It can be easily specify the message, icon, and title that will display the dialogue.

A message dialog box displays plain messages to the user and is created by using the static method showMessageDialog () of JOptionPane. The general form of showMessageDialog () method is:

 
by Dinesh Thakur

JDialog : Dialog boxes are JFrame restricted dependent on a main JFrame. The general JDialog dialog boxes are normally used for data requests.

 
by Dinesh Thakur

Displays a modal dialog with two buttons labeled "Yes" and "No".  These labels are not always terribly descriptive  program-specific actions that cause

 
by Dinesh Thakur

A combo box is a combination of a list component and text field component. It can consist of more than one item, however, displays only one item at any point of time. It also allows user to type their selection. Unlike list component, combo box allows user to select only one item at a time. A combo box is an object of JComboBox class.

 
by Dinesh Thakur

JApplet is a class that represents the Swing applet. It is a subclass of Applet class and must be extended by all the applets that use Swing. It provides all the functionalities of the AWT applet as well as support for menubars and layering of components. Whenever we require to add a component to it, the component is added to the content pane.

 
by Dinesh Thakur

The RoundRectangle2D class lets you draw a rectangle with corners rounded. The construction of the box is identical to that made ​​with the class Rectangle2D, the only difference in this case are two additional parameters to end of the constructor, which indicate the width and length of the curve defining each corner. The larger these values ​​will have higher level of rounding the corners.

 
 
by Dinesh Thakur

A button, also known as push button, is an active control that has a 3-dimensional appearance. It triggers an event when it is clicked or activated. Swing also provides an ability to associate an icon, a string, or both with the buttons. A push button is an object of JButton class.

 
by Dinesh Thakur

A menu bar represents a list of menus which can be added to the top of a top-level window. Each menu is associated with a drop-down list of menu items. The concept of menu bar can be implemented by using three Java classes: JMenuBar, Menu and JMenuitem. A menu bar is represented by the object of class JMenuBar in which only the default constructor is defined. A menu bar may consist of one or more menus represented by the objects of the class JMenu. A menu contains a list of menu items represented by the objects of the class JMenuitem.



 
by Dinesh Thakur

JMenuBar, which is a drop down menu bar at the top application, and JPopupMenu, a menu you get when you press the button right mouse on a particular area. The menus are comprised of different items:

 

Page 1 of 2