Java Tutorial

by Dinesh Thakur Category: Swing

Anonymous inner classes can also be used to provide a similar facility as that provided by inner classes.

 
by Dinesh Thakur Category: Swing

The most common use of inner classes is with event handling. An inner class can be used to implement a particular listener interface or to subclass a particular adapter. This has the benefit of separating out the control aspect of the interface from the display elements. It also means that the event handler inner class can inherit from a different class to the encompassing class.

 
by Dinesh Thakur Category: Swing

The listener class that implements the Listener interface must provide bodies for all of the methods of that interface. It is not a problem for all the semantic listener interfaces such as ActionEvent, ItemEvent, TextEvent, AdapterEvent as each of them declares only one method. However, for all the low-level listener interfaces where each interface contains multiple methods, implementing each method can be somewhat tedious, especially when we have to define methods in which we are not interested. For example: Suppose we are interested in setting up only one listener interface method windowClosing() of the WindowListener interface that causes the program to terminate. In that case, we would not only need to provide code for windowClosing() method but also need to write empty bodies for the other methods available in the WindowListener interface.

 
by Dinesh Thakur Category: Swing

Focus events occur when a component gains or loses keyboard focus. Objects representing focus events are created from FocusEvent Class. The corresponding listener interface for FocusEvent Class is FocusListener interface. Each listener for FocusEvent should implement the FocusListener interface.

 
by Dinesh Thakur Category: Swing

Window event occurs when window related activities such as closing, activating or deactivating a window are performed. Objects representing window events are created from WindowEvent class. The most common method of this class is

 
by Dinesh Thakur Category: Swing

Key events occur when a key is pressed, released or typed on a component. Objects representing key events are created from KeyEvent class. The corresponding listener interface for KeyEvent class is KeyListener. Each listener for KeyEvent should implement the KeyListener interface. The KeyListener interface defines three methods.

 
by Dinesh Thakur Category: Swing

Mouse event occurs when a mouse related activity is performed on a component such as clicking, dragging, pressing, moving or releasing a mouse etc. Objects representing mouse events are created from MouseEvent class.

 
by Dinesh Thakur Category: Swing

Item events occur when a user selects a choice item, a checkbox menu item or a list item. Objects representing item events are created from the ItemEvent class.

 
by Dinesh Thakur Category: Swing

The action event occurs when you perform an action on a component such as clicking a button, double clicking a list item, selecting a menu item etc. Objects representing action events are created from ActionEvent class.

 
by Dinesh Thakur Category: Swing

Event: An event is a signal to the program that something has happened. It can be triggered by typing in a text field, selecting an item from the menu etc. The action is initiated outside the scope of the program and it is handled by a piece of code inside the program. Events may also be triggered when timer expires, hardware or software failure occurs, operation completes, counter is increased or decreased by a value etc.

 
by Dinesh Thakur Category: Swing

Every swing component that is a subclass of JComponent can have a border. A border is a decorative element that virtually group components by drawing a line around them. By default, a component does not have a border.

 
by Dinesh Thakur Category: Swing

The SpringLayout layout manager is for a GUI's components to maintain their position relative to container edges or the edges of the other components after the GUI is resized. The SpringLayout layout manager lays out its container components according to a set of constraints specified by the user. Each constraint represented by a Spring object, controls the vertical or horizontal distance between two component edges. The edges can belong to the container itself or to any child of the container.

 
by Dinesh Thakur Category: Swing

Glue is an invisible component which is similar to a strut but it pushes the components as far away from each other as possible within the bounds of the box itself. You create an invisible component that represents Glue by calling the createGl ue () method for a Box object For example: The statements

 
by Dinesh Thakur Category: Swing

A rigid area filler is similar to pair of struts. It is an invisible component with a specific width and height. It can be created using the static method

 
by Dinesh Thakur Category: Swing

A strut is a fixed width invisible component that forces a certain amount of space between components. You can create a strut by calling the createHorizontalStrut () or createVerticalStrut () method depending upon what type of strut you want to create. The static method

 
by Dinesh Thakur Category: Swing

Although you can use the BoxLayou t directly, it is much more convenient to use javax.swing.BoxContainer class which has a built in BoxLayout layout manager. This class has some additional facilities that provide more flexibility in the arrangement of components than is provided by other containers such as JPanel object.

 
by Dinesh Thakur Category: Swing

The BoxLayout layout manager is similar to FlowLayout in that, the components are placed in the order in which they are added and each component gets to have its own size. But unlike FlowLayout, the BoxLayout layout manager arranges components in either a single row or a single column. In other words, the components you add to BoxLayout are added vertically from top to bottom or horizontally from left to right. In BoxLayout, components will not continue on the next line or columns when there is insufficient room. The components that are out of range will not be shown. This layout manager is useful for creating toolbars or vertical button bars.

 
by Dinesh Thakur Category: Swing

A panel in swing is similar to Panel in AWT, is a lightweight container that is designed to group a set of components, including other panels. It is visually represented as window that does not contain a title bar, menu bar or border. It is simplest of all the containers. Its default layout manager is FlowLayout.

 
by Dinesh Thakur Category: Swing

A scrolling pane is a container that can be used to hold any component that can be scrolled. By default, the list and textarea component do not scroll automatically when number of items in the list or text area component go beyond the displayed area. So to make these components scroll, you must insert them into the scrollpane. After you create a scrollpane containing a component (list or textarea), the scrolling pane should be added to the container in place of that component. A scrolling pane can be created by instantiating the JScrollPane class.

 
by Dinesh Thakur Category: Swing

A list components allows user to select a single or multiple items from a given list of items by clicking on each. By default, a user can select multiple items, however it is also possible to create a list from which user can choose only a single item.

 


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.