Monday, 7 January 2013

Learn JAVA swing

 

What is Java Swing?

     
Here, you will know about the Java swing. The Java Swing provides the multiple platform independent APIs interfaces for interacting between the users and GUIs components. All Java Swing classes imports form the import javax.swing.*; package.  Java provides an interactive features for design the GUIs toolkit or components like: labels, buttons, text boxes, checkboxes, combo boxes, panels and sliders etc. All AWT flexible components can be handled by the Java Swing. The Java Swing supports the plugging between the look and feel features. The look and feel that means the dramatically changing in the component like JFrame, JWindow, JDialog etc. for viewing it into the several types of window.
Here the following APIs interfaces and classes are available:
The following interfaces and it's descriptions to be used by the Java swing.
Interfaces
Descriptions
Action This interface performed the action with the ActionListener where the multiple controls are used for same purposes.
BoundedRangeModel This interface defines the data model of components like: sliders and progressBars.
ButtonModel It defines the state model for the buttons like: radio buttons, check boxes etc.
CellEditor This interface used by the developer for creating the new editor and it has the new components implement interfaces. The CellEditor implements the wrapper based approach.
ComboBoxEditor In this interface, the editor component used to JComboBox components.
ComboBoxModel This interface represents the data model in a list model with the selected items.
DesktopManager This interface has JDesktopPane object. The JInternalFrame implements in the JDesktopPane with the help of DesktopManager.
Icon This interface used to graphical representation of the components. It has fixed size picture.
JComboBox.KeySelectionManager This interface has KeySelectionManager and used for the combo box data model.
ListCellRenderer This interface used for paint the cell in the list with the help of "rubber stamps" .
ListModel This interface used for JList components method. It gets the value of each cell of list.
ListSelectionModel This interface indicates the components, which are stable or not. 
MenuElement This interface used where the any components are implements in the menu.
MutableComboBoxModel This interface extends from the ComboBoxModel. It is a mutable version of ComboBoxModel.
Renderer It defines the requirements of an object for displaying the values.
RootPaneContainer This interface uses the RootPane properties and it has the components like: JFrame, JInternalFrame and JWindow etc. 
Scrollable This interface provides the scrolling to show the large amount of data with the help of JScrollPane.
ScrollPaneConstants This interface used for JScrollPane components.
SingleSelectionModel This interface used to select the one index in a model.
SwingConstants You can set the components on the screen to own requirements.
UIDefaults.ActiveValue It constructs the DefaultListCellRenderer.
UIDefaults.LazyValue This enables one to store an entry in the default table. The entered value is not constructed until first time is a real value is created through it using LazyValue.createValue() method.
WindowConstants This interface has two methods setDefaultCloseOperation and getDefaultCloseOperation and provides the window close opration.
The following classes and it's descriptions to  be used by the Java swing.

Classes
Descriptions
AbstractAction This class handles the any types of action and provides JFC Action interface.
AbstractButton This class defines the nature of buttons and menu items.
AbstractCellEditor It provides a list and contents of the data model.
AbstractListModel This class defines the data model which provides the list with its contents.
ActionMap This class works with InputMap and performs any action when the key is pressed.
BorderFactory This class extends from Object and creates the Border instance in the factory.
Box It provides the fixed spaces between two components and uses the BoxLayout object of the layout manager.
Box.Filler This class participates in the Layout and uses the lightweight components.
BoxLayout This class uses the arranging the multiple components either horizontally or vertically. The Box container uses this class.
ButtonGroup This class used to create the multiple buttons in a ButtonGroup object.
CellRandererPane This class used to insert the components like: JList, JTable and JTree.
ComponentInputMap This class has ComponentInputMap constructor and creates the components with the help of InpuMap.
DebugGraphics It extends from the Graphics and used to debug the graphics
DefaultBoundedRangeModel This class provides the implementation of default BoundedRangeModel.
DefaultButtonModel This class implements the generic ButtonModel.
DefaultCellEditor It implements the TableCellEditor and TreeCellEditor for the table and tree cells.
DefaultComboBoxModel It provides the default model for combo boxes.
DefaultDesktopManager It implements the DesktopManager. The DesktopManager has the JInternalFrame for creating the internal fame in a frame.
DefaultFocusManager It provides the implementing the FocusManager.
DefaultListCellRanderer It implements the default ListCellRanderer
DefaultListCellRanderer.UIResource This extends the DefaultListCellRanderer and implementing in the UIResource.
DefaultListModel It extends the AbstractListModel and implementing the java.util.Vector.
DefaultListSelectionModel This class used for select the list in a data model.
DefaultSingleSelectionModel This class provides the default SingleSelectionModel.
FocusManager It handles all focus like: gainedFocus and lostFocus.
GrayFilter It extends the RGBImageFilter and used for disabling the image through the button.
ImageIcon This class implements the Icon and paints the icons from the images.
InputMap This class uses the ActionMap to performed the action when you press any key of keyboard. It bounds data between the input event and an object.
InputVerifier This class helps you when you works with the text fields through the focus.
JApplet This class extends the Applet and implements the Accessible and RootPaneContainer
JButton This class extends the AbstractButton and you can create the new button.
JCheckBox This class extends the JToggleButton and implements the check box in which buttons are selected or deselected.
JCheckBoxMenuItem It extends the JMenuItem and determines the items which is selected or deselected.
JColorChooser It extends the JComponent and implementing the Accessable. Here, you choose and manipulate the colors.
JComboBox This class extends the JComboBox. It provides the drop-down list where user select only one item or value at a time. But combo box is a combination of multiple text or buttons etc.
JComponent In java swing, All components are used the JComponent except the top-level containers like: JFrame, JDialog etc.
JDesktopPane This class extends the JLayeredPane and when you create the object of JInternalFrame to be maintained in the JDesktopPane. The JDesktopPane has DesktopManager.
JDialog It extends the Dialog. This class used to create the dialog window and when you want to create the custom dialog window with the help of JOptionPane method.
JEditorPane This class extends the JTextComponent. It edits the component by the EditorKit.
JFileChooser This class provides the facility to choosing the file.
JFrame It extends the Frame and supports the swing components architecture.
JInternalFrame This class extends from the JComponent and provides the facility to dragging, closing, resizing and menu bar of the internal frame. The JInternalFrame added into the JDesktopPane.
JInternalFrame.JDesktopIcon It displays the desktop icon and create the instance of JInternalFrame and iconify.
JLabel This class used to show the small text and image.
JLayeredPane It has JFC/Swing container that can be used to overlap the components to each other.
JList This class used to create a list where you select the one or more than objects.
JMenu This class used to create a new menu where you add the JMenuItems. When you select the item then shows the popup menu items in the JMenuBar.
JMenuBar It used to create a new menu bar where the JMenu objects are added.
JMenuItem This class used to create new menu items in the mebus. 
JOptionPane It used to create some different types of dialog box like: message dialog box, error dialog box etc.
JPanel It extends the JComponent and used to create a new panel.
JPassworkField It provides the single line text editing. Here, don't available the original characters but view type indication characters are available.
JPopupMenu This class used to create a popup menu. It provides small window where the various types of choices are available.
JPopupMenu.Separator Here the popup menu and the separator are available.
JProgressBar It shows the integer types values in percent within a bounded range to determine the working process.
JRadioButton It implements the radio button and shows the state of an item selected or deselected.
JRadioButtonMenuItem It extends the JMenuItem and implements the radio button menu item
JRootPane This class provides the component behind the scenes by JFrame, JWindow, JDialog etc. for providing the task-orientation and functionality.
JScrollBar This class used to create a scroll bar. It provides the view content area where you show the content to scroll this. 
JScrollPane It provides the scrollable view components.
JSeparator This class use the separator among the components.
JSlider This class provides a control to represent a numeric value by dragging the slider.
JSplitPane This class used to divides the two components graphically like: top and button, left and right.
JTabbedPane This class provides the tab component through which you can switch from one component to another component regarding to the specific tab button by clicking on that. 
JTable It provides the user interface component and represents the two dimensional data.
JTextArea It provides the multi line plain text area.
JTextField It provides the facility to editing the text in a single line.
JTextPane This class provides the component like JTexArea for multiple lines text with more capabalities.
JToggleButton It implements two state button that means selected or deselected.
JToggleButton.ToggleButtonModel It extends the DefaultButtonModel and provides the ToggleButton model.
JToolBar It provides set of command buttons icons that performs the different actions or controls.
JToolBar.Separator It provides the tool bar separator.
JToolTip It shows the tool tips related to it's components.
JTree It shows the data in a hierarchical way.
JTree.DynamicUtilTreeNode This extends the DefaultMutableTreeNode and create children nodes.
JTree.EmptySelectionModel It does not allows the any selection.
JViewPort It gives you about the underlying information.
JWindow It extends window and shows the any location or area on the desktop. It couldn't any title bar and window management buttons.
KeyStroke This class controls the key events on the keyboard for the equivalent device.
LayoutFocusTraversalPolicy This class conducts the sorting objects according to their size, type, position or orientation.
LookAndFeel It provides the dramatically changes in the component like frame related to the graphics for the application. Through this the application can be done very efficient and easier.
MenuSelectionManager It has menu selection hierarchy. 
OverlayLayout The layout manager arrange the components.
ProgressMonitor This class is used to monitoring the progress of any operation to be done.
ProgressMonitorInputStream This class creates a progress monitor to monitor the progress of reading input from the input stream. It cleanups all the rights when the stream is closed.
RepaintManager This class manage and override the repaint requests.
ScrollPaneLayout It implements the LayoutManager and manage the components like: scroll bar, row header, column header etc.
ScrollPaneLayout.UIResource It extends the ScrollPaneLayout and implements the UIResource.
SizeRequirements It calculates the size and positions of components.
SizeSequence It represents the order list of size and it's positions.
SwingUtilities This class has utilities methods for swing.
Timer Actions perform the predefined rate.
ToolTipManager It manages the all tool tips.
UIDefaults It extends the Hashtable and you set/get the value with the help of UIManager.
UIDefaults.LazyInputMap This class creates a Input Map through it's createValue() method. The array of key after binding is passed to the constructor of this. Example of binding of key is array of pressing key information (e.g. ctrl + c or alt + f).
UIDefaults.ProxyLazyValue This class is used to create a lazy value which is used to delay loading of the class to create instance for that.
UIManager This class has track of the current look and feel details.
UIManager.LookAndFeelInfo This is the nested class of UIManager class i.e. used for getting information about all the look and feels installed with the software development kit.
ViewportLayout It implements the LayoutManager and defines the policy for the layout.

Creating a Frame :


This program shows you how to create a frame in Java Swing Application. The frame in java works like the main window where your components (controls) are added to develop an application. In the Java Swing, top-level windows are represented by the JFrame class. Java supports the look and feel and decoration for the frame. 
For creating java standalone application you must provide GUI for a user. The most common way of creating a frame is, using single argument constructor of the JFrame class. The argument of the constructor is the title of the window or frame. Other user interface are added by constructing and adding it to the container one by one. The frame initially are not visible and to make it visible the setVisible(true) function is called passing the boolean value true. The close button of the frame by default performs the hide operation for the JFrame. In this example we have changed this behavior to window close operation by setting the setDefaultCloseOperation() to EXIT_ON_CLOSE value.
setSize (400, 400):
Above method sets the size of the frame or window to width (400) and height (400) pixels.
setVisible(true):
Above method makes the window visible.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE):
Above code sets the operation of close operation to Exit the application using the System exit method

Setting an Icon for a Frame in Java

In this section, you will learn how to set an icon for the frame in Java Swing.
This program helps us to set the icon (image) on the title bar of the frame. When you open frame or window the icon situated on the title bar is seen on the taskbar also. For this purposes, various methods as follows has been used:
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif"));
Above method sets the icon for the frame or window after getting the image using the Image class method named getImage().
frame.getDefaultToolkit():
This is the method of the Toolkit class which gets the default toolkit.
.

1 comment:

  1. Hey,
    Nice piece of information provided . I wanted to ask a question
    i am from Electronics background and the company i m placed in is an IT company as for now i have no other option i have to join this company only but the main problem is this that they work on java and i don't know anything about java. I saw many videos and even searched so came across http://www.wiziq.com/course/12145-the-6-week-complete-java-primer-with-training-certificate but i dont know how it is going to work for me. If anybody has taken this course please let me know..

    ReplyDelete