GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Similar documents
BASICS OF GRAPHICAL APPS

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Swing. By Iqtidar Ali

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Introduction to the JAVA UI classes Advanced HCI IAT351

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Internal Classes and Exceptions

Inheritance and Interfaces

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA. Assignment No. 4

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Window Interfaces Using Swing Objects

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Object Orientated Programming in Java. Benjamin Kenwright

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Window Interfaces Using Swing Objects

Graphic User Interfaces. - GUI concepts - Swing - AWT

CS 251 Intermediate Programming GUIs: Components and Layout

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

GUI Components: Part 1

Programming Languages and Techniques (CIS120e)

Systems Programming Graphical User Interfaces

encompass a group of features for building Graphical User Interfaces (GUI).

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Graphical User Interfaces (GUIs)

Swing from A to Z Some Simple Components. Preface

Graphical Applications

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Graphical User Interface (GUI)

5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16]

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

SINGLE EVENT HANDLING

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Graphical User Interface (GUI)

Graphical User Interfaces. Comp 152

Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p.

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

MODEL UPDATES MANIPULATES USER

Packages: Putting Classes Together

GUI in Java TalentHome Solutions

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5.

Programming Language Concepts: Lecture 8

1005ICT Object Oriented Programming Lecture Notes

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Java. GUI building with the AWT

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Lecture 9. Lecture

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Come & Join Us at VUSTUDENTS.net

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Graphical interfaces & event-driven programming

G51PRG: Introduction to Programming Second semester Applets and graphics

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Sri Vidya College of Engineering & Technology

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

CS Exam 1 Review Suggestions

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

Java Programming Lecture 6

2110: GUIS: Graphical User Interfaces

CS11 Java. Fall Lecture 4

Programmierpraktikum

H212 Introduction to Software Systems Honors

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Polymorphism. Object Orientated Programming in Java. Benjamin Kenwright

Jonathan Aldrich Charlie Garrod

First Name: AITI 2004: Exam 2 July 19, 2004

Chapter 6: Graphical User Interfaces

Part I: Learn Common Graphics Components

Window Interfaces Using Swing. Chapter 12

(Incomplete) History of GUIs

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Oracle 10g: Java Programming

More Swing. Chapter 14. Chapter 14 1

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Chapter 14. More Swing

Widgets. Widgets Widget Toolkits. User Interface Widget

Programming graphics

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

E Oracle 10g Java Bootcamp I v1

Basicsof. JavaGUI and SWING

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Transcription:

GUI Basics Object Orientated Programming in Java Benjamin Kenwright

Outline Essential Graphical User Interface (GUI) Concepts Libraries, Implementation, Mechanics,.. Abstract Windowing Toolkit (AWT) Java Foundation Classes (JFC) Today s Practical Review/Discussion

Graphical User Interfaces (GUI) Note this is a huge area Many books are devoted solely to this topic Today we will provide an overview on getting started with Java GUIs

Why is the Graphical User Interface (GUI) Important? What software packages have GUIs? What does the GUI offer? What are the different types of GUI?

Why is the Graphical User Interface (GUI) Important? Visual feedback/input Allows higher productivity Faster learning curve/usability Intuitive to the user Display/show more information/details Picture is worth a thousand words Allows colour/animations Provides more opportunities (e.g., video/games)

Question What does GUI stand for? a) Graphical User Interface b) Gimme Ur Internet c) Grand User Interface d) Graphical Useful Interface

Answer a) Graphical User Interface

GUI Overview To create a Java GUI, you need to understand Containers Event Event Handlers Layout managers Components Special features

AWT and JFC/Swing Early Java development used graphic classes defined in the Abstract Windowing Toolkit (AWT) See the java.awt packages. Java 2 introduced the JFC/Swing classes See the javax.swing packages Many AWT components have similar Swing counterparts An example, the AWT Button class corresponds to a more versatile Swing class called JButton. Swing does not generally replace the AWT; still use AWT for events and the underlying AWT event processing model

Standard GUI Components used to Create User Interfaces (Swing)

Containers A container is a special component that can hold other components The AWT class, as well as the Swing class, are containers Other containers include Frames A frame is a container that is free standing and can be positioned anywhere on the screen. Frames give the ability to do graphics and GUIs through applications Dialog boxes Panels Panes Toolbars

Example Containers (Top Level and General)

Example Special Containers

Events Every time the user types a character or pushes a mouse button, an event occurs Any object can be notified of the event All the objects have to do implement the appropriate interface and be registered as an event listener on the appropriate event source

Events, cont. Several events implemented in java.awt.awtevent subclasses (java.awt.event is deprecated) Defines a lot of constants

Events Handlers In the declaration for the event handler class, one line of code specifies that the class either implements a listener interface (or extends a class that implements a listener interface). public class MyClass implements ActionListener In the event handler class the method(s) in the listener interface must be implemented public void actionperformed(actionevent e) { /* code that "reacts" to the event */ } Register an instance of the event handler class as a listener on one or more components. mycomponent.addactionlistener(myclassinstance)

Events Handlers, cont. Often an event handler that has only a few lines of code is implemented using an anonymous inner class.

Events Handlers, cont. SwingApplication has two event handlers. Window closing (window events). frame.setdefaultcloseoperation (JFrame.EXIT_ON_CLOSE); Button clicks (action events). see previous slide. Types of events (listeners defined in java.awt.event)

WindowListener and MouseListener

Layout Managers A layout manager is an object that determines the manner in which components are displayed in a container There are several predefined layout managers defined in the Java standard class library

Layout Managers, cont. Every container has a default layout manager, but we can also explicitly set the layout manager for a container Each layout manager has its own particular rules governing how the components will be arranged Some layout managers pay attention to a component's preferred size or alignment, and others do not The layout managers attempt to adjust the layout as components are added and as containers are resized

Flow Layout A flow layout puts as many components on a row as possible, then moves to the next row Rows are created as needed to accommodate all of the components Components are displayed in the order they are added to the container The horizontal and vertical gaps between the components can be explicitly set Default for JPanel

Border Layout A border layout defines five areas into which components can be added The default for most GUIs

Box Layout A box layout organizes components either horizontally (in one row) or vertically (in one column) Special rigid areas can be added to force a certain amount of spacing between components By combining multiple containers using box layout, many different configurations can be created Multiple containers with box layouts are often preferred to one container that uses the more complicated gridbag layout manager

Other Layout Managers

"Atomic" Components The root in the component hierarchy is JComponent. The JComponent provides the following functionality to its descendants, e.g., JLabel, JRadioButton, and JTextArea Tool tips Borders Keyboard-generated actions Application-wide pluggable look and feel Various properties Support for layout Support for accessibility Double buffering

Basic Components

Non-Editable Displays

Editable Displays

Summary Overview Basic GUI Principles Abstract Windowing Toolkit (AWT) Java Foundation Classes (JFC) Apply Hands-On/Practical Understanding of GUIs

This Week Read Associated Chapters Review Slides Online Quizzes Java Exercises

Today s Practical Programming Exercises (Book): Chapter 12.1-12.5 (Only code not UML) Upload single.zip file containing all your java files (only java files). www.zjnu.xyz zip file name should be your student number, e.g., 29392929.zip Remember to comment your code, name/student number at the top of files. Organise your files so it s clear to identify each exercise (e.g., file names/folders) ch12_1.java, ch12_2.java,

Questions/Discussion