Java Tutorial

by Dinesh Thakur Category: Swing

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 Category: Swing

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 Category: Swing

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 Category: Swing

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 Category: Swing

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 Category: Swing
 
by Dinesh Thakur Category: Swing

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 Category: Swing
 
by Dinesh Thakur Category: Swing
 
by Dinesh Thakur Category: Swing

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 Category: Swing

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 Category: Swing

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 Category: Swing

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 Category: Swing

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 Category: Swing
 
by Dinesh Thakur Category: Swing

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 Category: Swing

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

 
by Dinesh Thakur Category: Swing

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 Category: Swing
 


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.