Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.

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
Graphical User Interfaces Java’s AWT and Swing APIs.
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Corresponds with Chapter 12
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
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 Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
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.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
GUI and event-driven programming An introduction.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
CS3 - AWT/Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
Java Programming Chapter 10 Graphical User Interfaces.
Welcome to CIS 083 ! Events CIS 068.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
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.
Field Trip #19 Animations with Java By Keith Lynn.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Layout Manager Summary
CSCI Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
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.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Object Oriented Programming.  Interface  Event Handling.
Computer Science 209 GUIs Model/View/Controller Layouts.
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.
Graphical User Interfaces Tonga Institute of Higher Education.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Module 13: Swing API Object Oriented Programming(Java)
A Quick Java Swing Tutorial
Chapter 9: Graphical User Interfaces
Provision for GUIs in Java
GUIs Model/View/Controller Layouts
Provision for GUIs in Java
Tim McKenna Layout Mangers in Java Tim McKenna
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Creating Graphical User Interfaces
Graphical User Interface
Presentation transcript:

Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6

Java Programming: Advanced Topics 2 Objectives Learn the characteristics of a graphical user interface Explore the contents of the Java Foundation Classes Discover how the JFC supports creating GUIs for the Java platform Design GUIs with layouts that dynamically adjust to screen resolution and window size Include predefined components such as text fields, buttons, and multimedia elements in your GUI

Java Programming: Advanced Topics 3 Objectives (Cont.) See how the JFC provides a framework for interacting with the user in event-driven programs Write code using component, container, and layout manager classes of the AWT and Swing State the name of the event class for any specified listener interface in the java.awt.event package Write code to implement the paintComponent method of a javax.swing.Jcomponent component

Java Programming: Advanced Topics 4 Main Features and Terminology of a GUI Components are predefined standard elements (such as buttons, text fields, frame windows, and dialog boxes) The layout managers control the way components are arranged within a container Graphics: drawing in the graphics context for a component Graphics context: is the area on the display screen where a component is positioned

Java Programming: Advanced Topics 5 Main Features and Terminology of a GUI (Cont.) Painting: the process of displaying components or refreshing the display of components on the screen Events can be triggered by the operating system or by user actions The adapter is a class that implements all the methods of the interface by providing empty methods for all of them Each listener interface that has more than one method also has a corresponding adapter class

Java Programming: Advanced Topics 6 Introducing the Java Foundation Classes The goal of the JFC is to simplify the development of 100% Pure Java programs for network or standalone environments The classes enable you to: –Design GUIs that reflect the operating system that is host to the JVM –Create your own platform-independent interface –Use a look and feel defined for the Java platform and common across all implementations of the JVM

Java Programming: Advanced Topics 7 Introducing the Java Foundation Classes

Java Programming: Advanced Topics 8 Introducing the Java Foundation Classes

Java Programming: Advanced Topics 9 Abstract Windowing Toolkit API

Java Programming: Advanced Topics 10 Abstract Windowing Toolkit API (Cont.)

Java Programming: Advanced Topics 11 Abstract Windowing Toolkit API (Cont.)

Java Programming: Advanced Topics 12 Event Model Define any class to be an event handler by implementing a listener interface Call a method of a component class to register the listener with the component When an event that relates to the component occurs, only the registered listeners are notified and passed a copy of the event The event model is consistent with the JavaBeans interface

Java Programming: Advanced Topics 13 Swing API The Swing API consists of more than 250 classes and 75 interfaces grouped into the following categories: –JComponent: extends the AWT class Container and a set of components that are subclasses of JComponent –Nonvisible support classes that provide important services –A set of related interfaces that are implemented by Swing component and support classes

Java Programming: Advanced Topics 14 Swing Components

Java Programming: Advanced Topics 15 Swing Components (Cont.)

Java Programming: Advanced Topics 16 Swing Components (Cont.)

Java Programming: Advanced Topics 17 Swing Components (Cont.)

Java Programming: Advanced Topics 18 Separable Model Architecture Swing components separate the manipulation of data associated with a component from the rendering or graphical-representation component and its contents The Swing API uses a separable model architecture Swing models use two different styles of notification: –Lightweight –Stateful The Swing API defines a set of model interfaces

Java Programming: Advanced Topics 19 Swing Model Interfaces

Java Programming: Advanced Topics 20 Swing Model Interfaces (Cont.)

Java Programming: Advanced Topics 21 An Example of JFC Program

Java Programming: Advanced Topics 22 Layout Managers Layout managers automate the positioning of components within containers Standard layout managers: –BorderLayout –FlowLayout –GridLayout –GridBagLayout –BoxLayout –CardLayout The javax.swing.JTabbedPane and javax.swing.JSplitPane containers in the Swing API have built-in layout characteristics

Java Programming: Advanced Topics 23 Layout Managers and Related Interfaces

Java Programming: Advanced Topics 24 Border Layouts The BorderLayout class implements the LayoutManager2 interface to support a container that holds up to five components: –North –South –West –East –Center By default, the JWindow, JFrame, and JDialog containers have border layouts

Java Programming: Advanced Topics 25 The BorderLayout Strategy

Java Programming: Advanced Topics 26 Flow Layouts The class FlowLayout implements the LayoutManager interface Components are arranged in a row across the area of the container Components in a flow layout retain their preferred size By default, JPanel objects have flow layouts

Java Programming: Advanced Topics 27 A FlowLayout Example

Java Programming: Advanced Topics 28 Grid Layouts The class GridLayout implements the LayoutManager2 interface GridLayout manager divides the area of the container into a grid of equally sized rows and columns Components are automatically put into the next cell, in a left to right order, filling rows from top to bottom

Java Programming: Advanced Topics 29 A GridLayout Example

Java Programming: Advanced Topics 30 Grid-Bag Layouts The class GridBagLayout implements the LayoutManager2 interface to support grid-bag layouts A grid-bag layout is based on a rectangular grid, and it uses a helper class, GridBagConstraints, to specify how each component should be located within the grid

Java Programming: Advanced Topics 31 A GridBagLayout Example

Java Programming: Advanced Topics 32 Events Events: objects that encapsulate changes in state that are initiated by the user or the operating system The AWT API includes the package java.awt.event of the classes that encapsulate the events that relate to the GUI components in your application or applet

Java Programming: Advanced Topics 33 AWT Event Classes

Java Programming: Advanced Topics 34 AWT Event Classes(Cont.)

Java Programming: Advanced Topics 35 Swing Event Classes

Java Programming: Advanced Topics 36 Selected Methods of the Event Classes

Java Programming: Advanced Topics 37 Selected Methods of the Event Classes (Cont.)

Java Programming: Advanced Topics 38 Events that Start Long Operations

Java Programming: Advanced Topics 39 Painting Painting: the act of drawing onto the graphics context of a component All objects that are instances of subclasses of java.awt.Component handle their own painting The key methods: –void paintComponent (Graphics context) –void paint (Graphics context) –void repaint (long time) –void update (Graphics context)

Java Programming: Advanced Topics 40 Basic Support for Graphics The AWT API provides basic graphics support through the class Graphics The drawing methods of the class Graphics are instance methods of the Graphics class, and each instance of Graphics is the graphics context for a component The Graphics class provides a number of methods for drawing onto a component

Java Programming: Advanced Topics 41 Java 2D API The basic support for drawing was lacking for high-quality graphics The goal was to create an API that addressed the needs of graphics professionals The Java 2D API was created and included as part of the JFC

Java Programming: Advanced Topics 42 Notable Java 2D Features

Java Programming: Advanced Topics 43 Summary The JFC consists of five major APIs, including the classes and interfaces in the AWT and Swing APIs that you use to program a GUI for an application or applet Layout managers are used to arrange the components in a way that adjusts for screen resolutions and window resizings Standard layout managers include BorderLayout, FlowLayout, GridLayout, GridBagLayout, Box, and CardLayout Each component class supports a number of events that are appropriate to its type of component

Java Programming: Advanced Topics 44 Summary (Cont.) The AWT contains a hierarchy of event classes for different kinds of user-initiated events, such as ComponentEvent, MouseEvent, KeyEvent, ItemEvent, TextEvent, and ActionEvent Each listener interface that has more than one method also has a corresponding adapter class Painting is the act of drawing onto the graphics context of a component, and drawing methods of the Graphics class are paintComponent, paint, and update methods of a component The goal of the Java 2D API addresses the needs of graphics professionals