Administrivia. CSSS Movie Night: Zombieland & Iron Man Date: Thurs., Mar 11 Time: 6 10 pm Location: DMP 310 Free pop & popcorn for every attendee!

Similar documents
Administrivia. CSSS Movie Night: Zombieland & Iron Man Date: Thurs., Mar 11 Time: 6 10 pm Location: DMP 310 Free pop & popcorn for every attendee!

Administrivia. Events this week Drop-In Resume and Cover Letter Editing Date: Tues., Mar 23 Time: 12:30 2:30 pm Location: Rm 255, ICICS/CS

Location: Planet Laser Interview Skills Workshop

Location: Planet Laser Interview Skills Workshop

JComponent. JPanel. JFrame. JFrame JDialog, JOptionPane. JPanel. JPanel

1 10 3:30 5: :30 1:30 206, ICICS/CS

Administrivia. IBM Info Session Date: Wed,, Jan 13 Time: 5:30 7 pm Location: Wesbrook 100

Administrivia. Events this week Drop-In Resume and Cover Letter Editing Date: Tues., Mar 23 Time: 12:30 2:30 pm Location: Rm 255, ICICS/CS

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

Administrivia. CPSC Winter 2008 Term 1. Department of Computer Science Undergraduate Events

Charlie Garrod Bogdan Vasilescu

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

Department of Computer Science Undergraduate Events

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

Dining philosophers (cont)

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Introduction to the JAVA UI classes Advanced HCI IAT351

Location: Planet Laser Interview Skills Workshop

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

Midterm assessment - MAKEUP Fall 2010

Java Programming Lecture 6

Charlie Garrod Michael Hilton

MIT AITI Swing Event Model Lecture 17

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Advanced Java Programming (17625) Event Handling. 20 Marks

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Local Search. (Textbook Chpt 4.8) Computer Science cpsc322, Lecture 14. Oct, 7, CPSC 322, Lecture 14 Slide 1

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

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

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

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

Systems Programming Graphical User Interfaces

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSIS 10A Assignment 7 SOLUTIONS

Basics of programming 3. Java GUI and SWING

CS Exam 1 Review Suggestions

More Swing. CS180 Recitation 12/(04,05)/08

Custom Data Models and Cell Renderers

Graphical interfaces & event-driven programming

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

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

CSE 8B Intro to CS: Java

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

Review sheet for Final Exam (List of objectives for this course)

Lighting/Shading II. Week 7, Mon Mar 1

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

Java: Graphical User Interfaces (GUI)

CS 134 Programming Exercise 7:

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Austin Community College Google Apps Calendars Step-by-Step Guide

Programming Languages and Techniques (CIS120)

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class.

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

To gain experience using recursion and recursive data structures.

Swing - JLabel. Adding a text (and HTML) labels to a GUI

Introduction to concurrency and GUIs

Getting Started. Using Aesop Successfully. Log on to Aesop. Create absences online or on the phone

Synchronized Methods of Old Versions of Java

AP CS Unit 11: Graphics and Events

CS 170 Java Programming 1. Week 15: Interfaces and Exceptions

I VE GOT A LITTLE LIST

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

The AWT Event Model 9

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

YEAH session #6. 6 March 2014, 5:30p-6:30p Miles Seiver

GUI Event Handlers (Part I)

Class 16: The Swing Event Model

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

CS 251 Intermediate Programming GUIs: Event Listeners

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

CS 11 java track: lecture 3

Searching for Information. A Simple Method for Searching. Simple Searching. Class #21: Searching/Sorting I

2110: GUIS: Graphical User Interfaces

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Class 27: Nested Classes and an Introduction to Trees

RAIK 183H Examination 2 Solution. November 11, 2013

JAVA NOTES GRAPHICAL USER INTERFACES

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

Basicsof. JavaGUI and SWING

CSC 161 SPRING 17 LAB 2-1 BORDERLAYOUT, GRIDLAYOUT, AND EVENT HANDLING

Jonathan Aldrich Charlie Garrod

Programming Languages and Techniques (CIS120)

Packages: Putting Classes Together

Graphical User Interface

Graphic User Interfaces. - GUI concepts - Swing - AWT

SampleApp.java. Page 1

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

JAVA NOTES GRAPHICAL USER INTERFACES

Graphical User Interfaces. Comp 152

Window Interfaces Using Swing Objects

Introduction. Introduction

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

Building Graphical User Interfaces. Overview

Swing from A to Z Some Simple Components. Preface

Workaround Swing Bugs

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

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

Declarations and Access Control SCJP tips

Transcription:

Department of Computer Science Undergraduate Events Events this week Drop-In Resume and Cover Letter Editing (20 min. appointments) Date: Thurs., March 11 Time: 11:30 am 2:30 pm Location: Rm 255, ICICS/CS Townhall Meeting for Combined Majors /Honours, Cogs, BA, B.Comm in CS Date: Thurs., March 11 Time: 12:30 2 pm Location: DMP 310 Lumch will be provided! CS Distinguished Lecture Series Featuring David Parkes Title: Incentive Mechanism Engineering in the Internet Age Date: Thurs., Mar 11 Time: 3:30 4:50 pm Location: DMP 110 CSSS Movie Night: Zombieland & Iron Man Date: Thurs., Mar 11 Time: 6 10 pm Location: DMP 310 Free pop & popcorn for every attendee! Events next week Interview Skills Practice Session Mon., March 15, 12 2 pm, Rm 202, ICICS/CS Transport Canada Info Session Tues., March 16, 4 6 pm, HENN 201 Financial Literacy 101 Wed., March 17, 12 1 pm, Angus 426 Townhall Meeting for CS Major/Honours Students Thurs., March 18, 12:30 2 pm, DMP 310 CS Distinguished Lecture Series Featuring Jeff Hawkins Thurs., March 18, 3:30 4:50 pm, DMP 110 1 Administrivia Assignment #3 is now looming closer Due Thursday March 18, 10:00pm Midterm exam Average and median about 65-66 Lab weeks start on Fridays from now on Final exam CPSC 211 - Apr 23, 7:00pm BCS section: DMP 101 2

Example: Inner Classes public class countclicksframe extends JFrame // Count and label in which count will be shown private int count; private JLabel countlabel; // Listener class private class Listen implements ActionListener public void actionperformed(actionevent ae) countlabel.settext("count = " + ++count); // Constructor public countclicksframe(string title) JButton jb = new JButton("Click me!"); jb.addactionlistener(new Listen()); cp.add(jb, BorderLayout.NORTH); Anonymous Inner Class When we need only a single instance of an inner class, we can create the class and its instance on the fly inside a statement. For readability reasons, this should only be done when the body of the class is very short. To create an instance of an anonymous subclass of class Myclass: MyClass myobject = new MyClass () public void overriddenfunc() System.out.println("Some message"); ;

Anonymous Inner Class (cont'd) To create an instance of an anonymous class that implements the interface SomeInterface: SomeInterface anobject = new SomeInterface () public void interfacefunc() System.out.println("Some message"); ; Anonymous classes do not have a constructor; they rely on the default constructor of their superclass. Example: Anonymous Inner Classes Here is the example from 3 slides ago, implemented using an anonymous inner class: public class countclicksframe extends JFrame // Count and label in which count will be shown private int count; private JLabel countlabel; // Constructor public countclicksframe(string title) JButton jb = new JButton("Click me!"); jb.addactionlistener(new ActionListener() public void actionperformed(actionevent ae) countlabel.settext("count = " + ++count); );

Adapter Classes Implementing all the methods of a listener can be tedious if we only care about one (or a small subset) of them. The MouseListener interface, for example, defines five methods. We don't want to have to provide implementations for all of them if we're interested only in the mouseclicked event. Swing provides adapter classes for some listeners: the adapter provides a default implementation (an empty body) for all the methods. The adapter can be subclassed to override the methods that we care about, without having to implement the other ones. Adapter Classes Examples: MouseAdapter implements MouseListener interface WindowAdapter implements WindowListener interface Code Example: frame.addwindowlistener(new WindowAdapter() public void windowclosing(windowevent e) confirmexitifunsaveddata(); ); Note the anonymous inner class in use here!

Focus Events At any point in time, exactly one component will receive key events (events generated when a key is pressed or released). This component is said to have the keyboard focus. Focus events occur when: The user clicks on a component that can acquire keyboard focus, for instance a text field (focusgained event). The user clicks somewhere else, causing the component to lose keyboard focus (focuslost event). The user hits the tab key to move from one text field to another. And more... Example: Focus Listener In an application, the following focus listener might be registered with the text fields in a dialog so that when a text field gains focus, all the text within that field is selected for the user. This makes it easy for a user to replace all the text in a field if they revisit it. private class TextFieldListener implements FocusListener public void focusgained(focusevent event) JTextField tf = (JTextField) event.getsource(); tf.selectall(); public void focuslost(focusevent event) // Do nothing when we lose focus.

Components and Models We use a Component to display data in a particular way. For example, the JList and a JTree classes are used to display a list (or tree) of items that can be selected by the user. Components and Models (cont d) In general, we want to separate the data (the model) from the way the data is displayed (the view). This makes it easy to change the way the data is presented to the user (the view) without making any changes to the way the data itself is represented (the model). It allows the application to manipulate the data without regard to the way the data is displayed. The more complicated Swing components such as JList, JTree and JTable do not store the data that they display. Instead, it is stored in another object called a model.

Components and Models (cont d) How do these components handle different types of data? Swing defines an interface that defines the behaviour (methods) that the model must support. The Component accesses the data only through the model's interface. The class to be displayed in the component implements this interface, in addition to its "own functionality". Example: Components and Models public class SimpleListModel implements ListModel int size; public SimpleListModel(int x) size = x; public int getsize() return size; public Object getelementat(int index) return new Integer(size + index * index); public void addlistdatalistener(listdatalistener l) public void removelistdatalistener(listdatalistener l)

Components and Models (cont) public class FunnyJList extends Jlist public FunnyJList(int x) super(new SimpleListModel(x)); setselectionmode(listselectionmodel.single_selection); addlistselectionlistener(new ListSelectionListener() public void valuechanged(listselectionevent e) JList source = (JList) e.getsource(); if (source.isselectionempty()) return; int row = source.getselectedindex(); SimpleListModel m = (SimpleListModel) source.getmodel(); int x = ((Integer) m.getelementat(row)).intvalue(); JOptionPane.showMessageDialog(null, x + ""); ); Exercises 2 nd Ed: Chapter 14 Questions P14.1, P14.4 3 rd Ed: Chapter 18 Questions P18.1, P18.4 4 th Ed: Chapter 18 Questions P18.8, P18.11