1 / 9

Introduction to Java Swing

Introduction to Java Swing. “We are the sultans of swing” – Mark Knopfler. What it is. Swing  is the primary  Java GUI widget toolkit . It is part of  Oracle 's  Java Foundation Classes  (JFC) — an  API  for providing a  graphical user interface  (GUI) for Java programs .

reina
Download Presentation

Introduction to Java Swing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler

  2. What it is • Swing is the primary JavaGUIwidget toolkit. It is part of Oracle's Java Foundation Classes (JFC) — an API for providing a graphical user interface (GUI) for Java programs. • More sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). • Provides a native look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel • Unlike AWT components, Swing components are not implemented by platform-specific code. Instead they are written entirely in Java and therefore are platform-independent.

  3. Swing Features • Light Weight - Swing component are independent of native Operating System's API as Swing API controls are rendered mostly using pure JAVA code instead of underlying operating system calls. • Rich controls - Swing provides a rich set of advanced controls like Tree, TabbedPane, slider, colourpicker, table controls • Highly Customizable - Swing controls can be customized in very easy way as visual appearance is independent of internal representation. • Pluggable look-and-feel- SWING based GUI Application look and feel can be changed at run time based on available values.

  4. Architecture (MVC) Swing API architecture follows loosely based MVC architecture in the following manner. • A Model represents component's data. • View represents visual representation of the component's data. • Controller takes the input from the user on the view and reflects the changes in Component's data. • Swing component have Model as a separate element and View and Controller part are clubbed in User Interface elements. Due to this, Swing has pluggable look-and-feel architecture.

  5. Swing Controls • UI elements : The core visual elements the user eventually sees and interacts with. GWT provides a huge list of widely used and common elements varying from basic to complex which we will cover in this tutorial. • Layouts: They define how UI elements should be organized on the screen and provide a final look and feel to the GUI (Graphical User Interface). This part will be covered in Layout chapter. • Behavior: These are events which occur when the user interacts with UI elements. This part will be covered in Event Handling chapter.

  6. Important Classes • Component Class : The class Component is the abstract base class for the non menu user-interface controls of AWT. Component represents an object with graphical representation. • Container Class: The class Container is the super class for the containers of AWT. Container object can contain other AWT components. • JComponentClass: The class JComponent is the base class for all Swing components except top-level containers. To use a component that inherits from JComponent, you must place the component in a containment hierarchy whose root is a top-level Swing container. • JLabelClass: The class JLabel can display either text, an image, or both. Label's contents are aligned by setting the vertical and horizontal alignment in its display area. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default. • JButtonClass: The class JButton is an implementation of a push button. This component has a label and generates an event when pressed. It can have Image also. Etc………………

  7. Important Interfaces SWING Event Listeners  The Event listener represent the interfaces responsible to handle events. Java provides us various Event listener classes but we will discuss those which are more frequently used. Every method of an event listener method has a single argument as an object which is subclass of EventObject class. For example, mouse event listener methods will accept instance of MouseEvent, where MouseEvent derives from EventObject. • ActionListenerInterface : The class which processes the ActionEvent should implement this interface.The object of that class must be registered with a component. The object can be registered using the addActionListener() method. When the action event occurs, that object's actionPerformed method is invoked. • ComponentListenerInterface: The class which processes the ComponentEvent should implement this interface.The object of that class must be registered with a component. The object can be registered using the addComponentListener() method. Component event are raised for information only. Etc……

  8. Look into code samples…..

  9. Sources (Most important part) • http://www.tutorialspoint.com/swing/swing_quick_guide.htm • http://www.tutorialspoint.com/swing/ • http://en.wikipedia.org/wiki/Swing_(Java) • http://docs.oracle.com/javase/tutorial/uiswing/

More Related