DAT602 Database Application Development Lecture 6 JAVA Swing.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Introduction to JFC Swing Written by Adam Carmi. Agenda About JFC and Swing Pluggable Look and Feel Swing Components Borders Layout Management Events.
Things to mention public static void main(String [] args) imports comments –block comments /* … */ –single-line comments // –javadoc comments and tags.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
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.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Creating GUIs in Java using Swing David Meredith Aalborg University.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
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 --
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
JAPPLET.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
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.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Next week: »No Lectures »No Labs »Recitation.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
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.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
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.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
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)
1 Lecture 8: User Interface Components with Swing.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
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:
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Module 13: Swing API Object Oriented Programming(Java)
A Quick Java Swing Tutorial
Welcome To java
Provision for GUIs in Java
A First Look at GUI Applications
University of Central Florida COP 3330 Object Oriented Programming
A Quick Java Swing Tutorial
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
A Quick Java Swing Tutorial
Chapter 17 Creating User Interfaces
Graphical User Interface
Presentation transcript:

DAT602 Database Application Development Lecture 6 JAVA Swing

Library of JAVA. In JAVA’s library, different packages contain classes with different functions. java.langjava.iojava.util javax.swing… Developers must import corresponding package in the resource code before using it. Database Application Development - Lecture 6

JFC and Swing JFC is short for Java Foundation Classes, which encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. This lecture’s topic is javax.swing. Database Application Development - Lecture 6

What is in javax.swing package ? What can swing provide to us ? Database Application Development - Lecture 6 FeatureDescription Swing GUI ComponentsIncludes everything from buttons to split panes to tables. Pluggable Look-and-Feel SupportThe look and feel of Swing applications is pluggable, allowing a choice of look and feel. Accessibility APIEnables assistive technologies, such as screen readers. Java 2D APIEnables developers to easily incorporate high-quality 2D graphics, text, and images in applications and applets. InternationalizationLanguage support.

What is container in JAVA swing ? Container is a set of Java classes, a container could be JFrame, JApplet or JDialog. These containers can be used for containing other Java swing components or containers. Database Application Development - Lecture 6

To appear onscreen, every GUI component must be part of a containment hierarchy. A containment hierarchy is a tree of components that has a top-level container as its root. Database Application Development - Lecture 6

containment hierarchy for this example's GUI

Database Application Development - Lecture 6 Top-Level Containers and Containment Hierarchies Each program that uses Swing components has at least one top-level container. This top- level container is the root of a containment hierarchy — the hierarchy that contains all of the Swing components that appear inside the top-level container.

The Root Pane Each top-level container relies on a reclusive intermediate container called the root pane. Database Application Development - Lecture 6

How to add a component to pane ? Here's the simple code that add a label to a container. container.add(yellowLabel, BorderLayout.CENTER); yellowLabel is a Label component. BorderLayout.CENTER indicate which kind of layout this component applied, and its position. Database Application Development - Lecture 6

In next slides, you will see some useful swing components. Button, Label, List, Panel, Password Field, Scroll Pane, Text Field. Database Application Development - Lecture 6

First, let’s see the JButton. In this part, we’ll use ButtonDemo for illustration.

Button. If you want using swing’s button component, you have to import following package in the beginning of your code. package: javax.swing.JButton import javax.swing.JButton; Database Application Development - Lecture 6

How to create a JButton ? JButton b1 = new JButton("Disable middle button", leftButtonIcon); A Swing button can display both text and an image. Database Application Development - Lecture 6

After a JButton being created, some properties should be set. b1 = new JButton("Disable middle button", leftButtonIcon); b1.setVerticalTextPosition(AbstractButton.CENTER); b1.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to- right locales b1.setMnemonic(KeyEvent.VK_D); b1.setActionCommand("disable"); Database Application Development - Lecture 6

After b1 being created, we also need to add a action listener to this new button. b1.addActionListener(this); What is action listener ? Action listener is a action capturer, it is used for notifying every time the user clicks the button. Database Application Development - Lecture 6

After all properties of button being set, and the action listener being bound with this button, then we can add this button to its higher level container. for example, add button b1 to a pane: pand.add(b1); Database Application Development - Lecture 6

For response the command from buttons, we should create a function to process different commands. public void actionPerformed(ActionEvent e) { if ("disable".equals(e.getActionCommand())) { b2.setEnabled(false); b1.setEnabled(false); b3.setEnabled(true); } Database Application Development - Lecture 6

JList A JList presents the user with a group of items, displayed in one or more columns, to choose from. Lists can have many items, so they are often put in scroll panes. Database Application Development - Lecture 6

Create and initializing a List JList list = new JList(listModel); //create a instance of Jlist list.setSelectionMode(ListSelectionModel.SINGLE_SELECT ION); // set a selection model list.setSelectedIndex(0);// the default selected item list.addListSelectionListener(this); // add a listener list.setVisibleRowCount(5); // number of visible records Database Application Development - Lecture 6

Choose a list model If you initialize a list with an array or vector, the constructor implicitly creates a default list model. The default list model is immutable — you cannot add, remove, or replace items in the list. ArrayList data = new ArrayList(); list = new JList(data); //data has type Object[] Database Application Development - Lecture 6

Choose a list model To create a list whose items can be changed individually, set the list‘s model to an instance of a mutable list model class, such as an instance of DefaultListModel. You can set a list's model when you create the list or by calling the setModel method. list.setModel(ListModel model); Database Application Development - Lecture 6

List selection mode you can use the method setSelectionMode to set the selecting model. SINGLE_SELECTIONSINGLE_INTERVAL_SELECTIONMULTIPLE_INTERVAL_SELECTIO Database Application Development - Lecture 6

Adding Items to and Removing Items from a List Before introduce add and remove operation. Here we creates a mutable list model object, puts the initial items in it, and uses the list model to create a list. We create a list for our example first. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Alan Sommerer"); JList list = new JList(listModel); Database Application Development - Lecture 6

Add a element to list. example: listModel.insertElementAt(employeeName.getText(), index); employeeName is a text field which is used for input new employee’s name. index is used for indicating where this new element be inserted. NOTE: add new element to the object list contains. Database Application Development - Lecture 6

Remove an element from list listModel.remove(index); index is used for indicating which element should be removed. You can indicate index manually, or you can use JList’s method getSelectedIndex to get the selected element’s index. Database Application Development - Lecture 6

Scroll Panes A JScrollPane provides a scrollable view of a component. When screen real estate is limited, use a scroll pane to display a component that is large or one whose size can change dynamically. Database Application Development - Lecture 6

Hot to create and initialize scroll pane ? JList list = new JList(array); JScrollPane scrollPane = new JScrollPane(list); You should also add this scroll pane to a higher level container. example: rootPane.add(scrollPane, BorderLayout.CENTER); Database Application Development - Lecture 6

Reference ing/components/index.html Database Application Development - Lecture 6