Published on

Hariprasanna V (9843824677)

  • 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

No notes for slide


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