Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interfaces
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 36 JTable and JTree.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Java Programming Chapter 10 Graphical User Interfaces.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
MVC and Swing IAT 351 Week 7 Lecture/tutorial Lyn Bartram.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
CSE 219 Patterns in Programming More Design Patterns.
Tables CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Trees CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
OOP (Java): GUI Intro/ OOP Objectives – –use an image viewer application to introduce Java's GUI features Semester 2,
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 31 JTable and JTree.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Advanced Java Class Events. change in state initiated by system or user java.util.EventObject java.awt.event java.swing.event.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
A Quick Java Swing Tutorial
Welcome To java
A First Look at GUI Applications
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Course Outcomes of Advanced Java Programming AJP (17625, C603)
A Quick Java Swing Tutorial
Advanced Programming in Java
Graphical User Interface
Presentation transcript:

Swinging in Your Java Playground

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

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

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.

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.

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); }

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(); }

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

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

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.

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.

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.

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

Other Details Components are lightweight Swing runs on any JDK 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.