Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Corresponds with Chapter 12
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
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)
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.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
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.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
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.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
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 --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
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
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 Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
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.
– 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 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
CS Lecture 00 Swing overview and introduction Lynda Thomas
Concurrent Programming and Threads Threads Blocking a User Interface.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
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.
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.
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.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Basics of GUI Programming Chapter 11 and Chapter 22.
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 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.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
A Quick Java Swing Tutorial
Provision for GUIs in Java
A First Look at GUI Applications
University of Central Florida COP 3330 Object Oriented Programming
Provision for GUIs in Java
Ellen Walker Hiram College
Steps to Creating a GUI Interface
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach

2 Objectives Event-Based Programming Creating a Swing-Based Window Adding a Window Closing Event Handler Adding a Button Component Common Programming Errors

3 Event-Based Programming Event-based programs provide fully functioning GUIs An event is initiated by a user action A program must: Correctly assess which specific event has occurred Provide the appropriate code to perform an action based on the identified event

4

5 Event-Based Programming (continued) Actions that trigger events include: Placing the mouse pointer over a button and clicking the left mouse button Using the TAB key until the desired button is highlighted with a dotted line then pushing the Enter key Pressing an accelerator key (shortcut key) The sequence of events in a program are controlled by the user

6 Event-Based Programming (continued) Programmer provides: Code to create GUI Code to appropriately process events Java provides a set of objects for coding GUIs: AWT (abstract window toolkit) Older GUI components Swing Newer GUI components

7

8 Swing Components Examples Top-Level Container – JFrame, JApplet, JWindow Intermediate Container – JPanel, JInternalFrame Atomic – JButton, JCheckBox, JTextField

9 The Event-Based Model Operating system: Has total control of computer Never relinquishes control to any executing programs Most executing programs spend the majority of their time in a sleep type of mode When an event occurs: The operating system passes event information to the appropriate application Permits the application to take action

10 Containment Hierarchy Hierarchy of component placement Consists of one and only one top-level container Any number of other intermediate containers And/or atomic components JFrame is most commonly used as a top-level container Heavyweight components (earlier Java term = top- level containers) are responsible for interfacing with the operating system

11 Containment Hierarchy (continued) A content pane (next level of hierarchy) is an internal component provided by each top- level container All of the visible components displayed by a GUI must be placed on a content pane Menu bar: Can be optionally added to a top-level container Placed outside of a content pane

12 Containment Hierarchy (continued) Layout manager: Defines how components are positioned and sized within a container’s content pane Default placement can always be changed By explicitly specifying another layout manager Lightweight components: Intermediate containers and atomic components Do not interface with the operating system

13 JFrame automatically provides a root pane, which in turn contains the content pane. Generally, not concerned with root pane.

14 Layout managers Each top and intermediate-level containers has a default layout manager that defines the components position and size withing the container’s content pane. You can always change the default layout by specifying another layout manager (chapter 10). The six layout managers currently available are:

15

16 Lightweight Components intermediate containers and atomic components do not interface directly with the operating system (hence lightweight)

17

18 Creating a Swing-Based Window Two predominant approaches: Construct a GUI as a separate class using Swing components Construct a GUI object using Swing components from within the main() method

19 Creating a Swing-Based Window (continued) Create JFrame: JFrame mainFrame = new JFrame("First GUI Window"); Setting size: syntax: objectReferenceName.setSize(width, height) mainFrame.setSize(300,150);

20

21 Could also use a single statement jFrame mainFrame = new JFrame(“First Gui Window”);

22 Creating a Swing-Based Window (continued) Display JFrame: Use show() Or setVisible(true)

23 import javax.swing.*; public class FirstWindow extends JFrame { private JFrame mainFrame; public FirstWindow() // a constructor { mainFrame = new JFrame("First GUI Window"); mainFrame.setSize(300,150); mainFrame.show(); } public static void main(String[]args) { new FirstWindow(); } } // end of class Provides access to all public and protected methods in the JFrame class

24 Look and Feel Refers to: How a GUI appears on screen How a user interacts with it Swing package: Supports four look and feel types If no look and feel is specified, the default Java look and feel is used

25 To implement a specific look and feel, this code must be contained in a try and catch block.

26