CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

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.
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
Chapter 7 Event-Driven Programming and Basic GUI Objects.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Building Graphical User Interfaces Overview Constructing GUIs Interface components GUI layout Event handling Objects First with Java - A Practical.
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 Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
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 
GUI Programming in Java
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
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.
Copyright © 2002, Systems and Computer Engineering, Carleton University Gui1.ppt * Object-Oriented Software Development Part 18 Building.
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.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
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.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Next week: »No Lectures »No Labs »Recitation.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
OOP (Java): GUI Intro/ OOP Objectives – –use an image viewer application to introduce Java's GUI features Semester 2,
Programming with Java’s Swing API February 4, 2003 CMPS Advanced Programming Graphical User Interfaces.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces 2.0.
Building Graphical User Interfaces Overview Constructing GUIs Interface components GUI layout Event handling Objects First with Java - A Practical.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1 COS 260 DAY 24 Tony Gauvin. 2 Agenda Questions? 10 th Mini Quiz Corrected –So-so results Capstone progress report over due Course evaluations Assignment.
Advanced Java Class Events. change in state initiated by system or user java.util.EventObject java.awt.event java.swing.event.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
1 IM103 week 10 Enhancing the user interface By the end of lecture you should be able to:  distinguish between heavyweight and lightweight components;
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
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:
Building Graphical User Interfaces Overview Constructing GUIs Interface components GUI layout Event handling © 2017 Pearson Education, Inc. Hoboken,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
A First Look at GUI Applications
A Quick Java Swing Tutorial
Building Graphical User Interfaces
COS 260 DAY 23 Tony Gauvin.
CSE 114 – Computer Science I Event Programming
Ellen Walker Hiram College
COS 260 DAY 23 Tony Gauvin.
COS 260 DAY 23 Tony Gauvin.
Graphical User Interface
1 Graphical User Interfaces
A Quick Java Swing Tutorial
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)

2.0

Overview Constructing GUIs Components Event handling

AWT and Swing

AWT (Abstract Window Toolkit) is a thin layer of code on top of the OS, whereas Swing is much larger. AWTis a thin layer of code on top of the OS, whereas Swing is much larger. Using AWT, you have to implement a lot of things yourself, while Swing has them built in. Swing implements GUI functionality itself rather than relying on the host OS, it can offer a richer environment on all platforms Java runs on. AWT is more limited in supplying the same functionality on all platforms because not all platforms implement the same-looking controls in the same Ways.

Swing components are called "lightweight" because they do not require a native OS object to implement their functionality. JDialog and JFrame are heavyweight, because they do have a peer. So components like JButton, JTextArea, etc., are lightweight because they do not have an OS peer. A "peer" is a widget provided by the operating system, such as a button object or an entry field object.

Elements of a frame Title Menu bar Content pane Window controls

Creating a frame import java.awt.*; import java.awt.event.*; import javax.swing.*; // comment omitted. public class ImageViewer { private JFrame frame; /** * Create an ImageViewer show it on screen. */ public ImageViewer() { makeFrame(); } // rest of class omitted. }

/** * Create the Swing frame and its content. */ private void makeFrame() { frame = new JFrame("ImageViewer"); Container contentPane = frame.getContentPane(); JLabel label = new JLabel("I am a label. I can display some text."); contentPane.add(label); frame.pack(); frame.setVisible(true); } The content pane

Adding menus JMenuBar Displayed below the title. Contains the menus. JMenu e.g. File. Contains the menu items. JMenuItem e.g. Open. Individual items.

private void makeMenuBar(JFrame frame) { JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); // create the File menu JMenu fileMenu = new JMenu("File"); menubar.add(fileMenu); JMenuItem openItem = new JMenuItem("Open"); fileMenu.add(openItem); JMenuItem quitItem = new JMenuItem("Quit"); fileMenu.add(quitItem); }

Event handling Events correspond to user interactions with components. Components are associated with different event types. Frames are associated with WindowEvent. Menus are associated with ActionEvent. Objects can be notified when an event occurs. Such objects are called listeners.

Centralized event receipt A single object handles all events. Implements the ActionListener interface. Defines an actionPerformed method. It registers as a listener with each component. item.addActionListener(this) It has to work out which component has dispatched the event.

public class ImageViewer implements ActionListener { … public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if(command.equals("Open")) { … } else if (command.equals("Quit")) { … } … } … private void makeMenuBar(Jframe frame) { … openItem.addActionListener(this); … }

Dialogs Modal dialogs block all other interaction. Forces a response from the user. Non-modal dialogs allow other interaction. This is sometimes desirable. May be difficult to avoid inconsistencies.

JOptionPane standard dialogs Message dialog Message text plus an OK button. Confirm dialog Yes, No, Cancel options. Input dialog Message text and an input field. Variations are possible.

A message dialog private void showAbout() { JOptionPane.showMessageDialog(frame, "ImageViewer\n" + "Version 0.2", "About ImageViewer", JOptionPane.INFORMATION_MESSAGE); }

Dialog message types ERROR_MESSAGE INFORMATION_MESSAGE WARNING_MESSAGE QUESTION_MESSAGE

Review Pre-defined components simplify creation of sophisticated GUIs. Many components recognize user interactions with them. Reactive components deliver events to listeners.

THANK YOU.