Your SlideShare is downloading. ×
  • Like
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply



Hariprasanna V (9843824677)

Hariprasanna V (9843824677)

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Swinging in Your Java Playground
  • 2. Background
    • Swing is a part of the Java Foundation Classes (JFC).
    • The JFC is made up of features intended to give a programmer all the tools necessary to build enterprise applications.
      • Swing Components
      • Pluggable Look and Feel
      • Accessibility API
      • Java 2D API
      • Drag and Drop Support
  • 3. Swing Features
    • Built on top of AWT 1.1, taking your 1995 school playground into 2000 and beyond
    • New components exist in Swing
      • Tables, Trees, Sliders, Progress Bars, Internal Frames, and Text Components.
    • Tooltips can appear over GUI Components
    • Bind Keyboard events to GUI Components
    • Easily extendible to create Customized Components
  • 4. Swing Design Model/View/Controller Architecture
    • Model - The state data for a component. For example, a Choice would contain all the items that could be chosen. This data remains constant no matter what it’s representation is on the screen.
    • View - The way a component actually appears when it is drawn on the screen
    • Controller - The way a component interacts with the events that occur.
  • 5. Taking Turns on a Swing Component (Event Handling)
    • When a component receives input, it fires events. An Object can register to receive those events by being added as a Listener to the Component.
    • A Component can have multiple objects listening for its events.
    • When the listening Object handles an event, it can do something to the Component or something else entirely.
  • 6. Taking Turns on a Swing Component (Event Handling) Example public class ClickEvent extends JFrame implements ActionListener { private JButton click = new JButton("Click Me"); private JTextField welcomeText = new JTextField(); private JPanel thePanel = new JPanel(); public ClickEvent() { super("Event Example"); setSize(400,300); thePanel.setLayout(new GridLayout(2,1)); //this.getContentPane().add(click,BorderLayout.NORTH); thePanel.add(click); thePanel.add(welcomeText); this.getContentPane().add(thePanel,BorderLayout.CENTER); click.addActionListener(this); this.setVisible(true); }
  • 7. Taking Turns on a Swing Component (Event Handling) Example public void actionPerformed(ActionEvent e) { welcomeText.setHorizontalAlignment(JTextField.CENTER); welcomeText.setText("Hello Linux User's Group"); } public static void main(String[] args) { ClickEvent clickEvent1 = new ClickEvent(); } }
  • 8. JTree Component
    • The visual representation of data that is organized in tree format
      • Root, there is only 1 of these for a tree
      • Node, any entry in the tree
      • Leaf, any node without a child node
    • Two Interfaces:
      • TreeModel - how to work with the data
      • TreeSelectionModel - how to select nodes within the tree
  • 9. JTree Component Continued
    • Node Interface: TreeNode, The basic piece of the tree
      • Contains the basic methods needed by the TreeModel to manipulate the data
    • All of the interfaces have Default implementations so that you don’t have to start from scratch
  • 10. JTree Component Continued
    • Events
      • TreeExpansionEvent, When a node has been expanded or collapsed
      • TreeSelectionEvent, A row (path) has been selected or, if multiple rows can be selected, a row has been added or removed from that group selection.
  • 11. JTable Component
    • The visual representation of data in a table format. It is very useful to display data from databases in this format.
      • Column is the basic unit of the Table. The data represented in it is consistent
      • Row the collection of columns that uniquely identifies an entity.
      • Cell the location at a particular row and column of data.
  • 12. JTable Component Continued
    • Two Interfaces:
      • TableColumnModel manages selection in the column and spacing of the column in the table.
      • TableModel provides all the information concerning the rows and columns in the table as well as access to the data found in the cells.
    • Again, both interfaces have Default implementations.
  • 13. JTable Component Continued
    • Events
      • TableColumnEvent used to notify that a column model has changed. For example, that a column has been added, removed, or moved.
      • TableModelEvent used to notify that the TableModel has changed and/or that rows/column data has changed
  • 14. Other Details
    • Components are lightweight
    • Swing runs on any JDK 1.1.5 or higher does not need to be downloaded for JDK 1.2; it is part of the core JDK.
    • Java.swing.border package which contain 8 predefined classes for borders that can be placed around a component.
    • Lots of classes exist to provide editing within the complex components.