CSC207 Week 4. Larry Zhang

Similar documents
CSC207 Week 3. Larry Zhang

Graphical User Interface (GUI)

Graphical User Interfaces (GUIs)

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

Lab 08. Command Line and Git

Graphical User Interface (GUI)

CSE 331 Software Design & Implementation

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


Programming Languages and Techniques (CIS120)

CSE 332: Data Structures and Parallelism Winter 2019 Setting Up Your CSE 332 Environment

Agenda. - Final Project Info. - All things Git. - Make sure to come to lab for Python next week

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

EPITA Première Année Cycle Ingénieur. Atelier Java - J5

GUI Forms and Events, Part II

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

Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

Part I: Learn Common Graphics Components

CS Exam 1 Review Suggestions

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 :) )

Java Programming Lecture 6

To gain experience using GUI components and listeners.

CS108, Stanford Handout #22. Thread 3 GUI

SD Module-1 Advanced JAVA

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

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

Introduction to concurrency and GUIs

SD Module-1 Advanced JAVA. Assignment No. 4

IT101. Graphical User Interface

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

Class 16: The Swing Event Model

Distributed Collaboration - Assignment 1: Multi-View 1-User IM

CSE 331 Software Design & Implementation

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

Midterm assessment - MAKEUP Fall 2010

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

Swing from A to Z Some Simple Components. Preface

More About Objects and Methods

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Revision Control. How can 4. Slides #4 CMPT 276 Dr. B. Fraser. Local Topology Simplified. Git Basics. Revision Control:

Using GitHub to Share with SparkFun a

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Software Development I

EGit/Gerrit Hands-on training #1: Installation and Configuration

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

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

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

Java IDE Programming-I

Phase 2: Due 11/28/18: Additional code to add, move and remove vertices in response to user mouse clicks on the screen.

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

JDirectoryChooser Documentation

Lab 4: Shell Scripting

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Windows and Events. created originally by Brian Bailey

8. Polymorphism and Inheritance

(Incomplete) History of GUIs

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

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

Technology Background Development environment, Skeleton and Libraries

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

Packages: Putting Classes Together

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

CS 251 Intermediate Programming GUIs: Components and Layout

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

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

Final Exam CS 251, Intermediate Programming December 13, 2017

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Developing Android applications in Windows

Java Programming Lecture 7

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

How to get started using the JSL

SINGLE EVENT HANDLING

SECTION 2: HW3 Setup.

Address book. Presenting the Java assignment about an Address Book v

11. Abstract Classes and Interfaces

Upon completion of the second part of the lab the students will have:

CS1004: Intro to CS in Java, Spring 2005

Handouts. 1 Handout for today! Recap. Homework #2 feedback. Last Time. What did you think? HW3a: ThreadBank. Today. Small assignment.

UI Software Organization

CSC369 Lecture 2. Larry Zhang

Commands. Written commands can be reused, cataloged, etc. Sometimes they also contain "undo" commands, too.

GUI Software Architecture

GUI Event Handlers (Part I)

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!

CS 11 java track: lecture 3

AP CS Unit 11: Graphics and Events

1. (5 points) In your own words, describe what an instance is.

Design Patterns and Frameworks Command

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

A L A TEX-oriented intro to Git

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Object Oriented Design & Patterns. Part 1

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

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Transcription:

CSC207 Week 4 Larry Zhang 1

Logistics A1 Part 1, read Arnold s emails. Follow the submission schedule. Read the Q&A session in the handout. Ask questions on the discussion board. Submit on time! Don t forget to push! After each submission checkpoint, if you think you can improve what you previously submitted, improve it anyway. Doesn t hurt. 2

Resolving Git Conflicts Rename your current repo folder to something like repo_i_messed_up. Don t delete it because it may contain uncommitted work. git clone again to re-download a fresh copy of the repo from the server Go into the fresh repo, see what s the status in there, and manually apply the new changes (copy-n-paste lines of code) from files in repo_i_messed_up to the fresh repo. Commit and push the new changes. In Eclipse, you may need to re-create the workspace and the projects. 3

Dynamic Binding class Person { public String hello() { return I am a person ; } } class Student extends Person { @Override public String hello() { return I am a student ; } } Student s1 = new Student( Alice, 22); Person p1 = s1; String x = p1.hello(); // Which hello() will be called? p1 is a reference that refers Student s1 as a Person. Java remembers that s1 is created as a Student. When calling p1.hello(), Java knows that what p1 is referring to is a Student, and it will invoke the method hello() that is implemented in the Student class. So p1.hello() returns is I am a student. Read more about dynamic binding here: https://stackoverflow.com/questions/190172 58/static-vs-dynamic-binding-in-java 4

Static Binding vs Dynamic Binding When you have multiple methods with the same name, how does Java decide which one to invoke? // Static binding happens at compile // time, based on type information. // Dynamic binding happens at runtime // time (cannot be sure until running, so // impossible to bind at compile time), // based on the calling Object. public int hello(int x) { return 1; } public int hello(string s) { reteurn 2; } int r1 = hello(3); // r1 = 1 int r2 = hello( 3 ); // r2 = 2 Person p; int r = random.nextint(5); if (r == 3) { p = new Student( Alice ); } else { p = new Doctor( Who ); } p.hello(); //depend on what Object p is referring to. 5

NEXT TOPIC Interface 6

Interface in Java Interface is like a special kind of class. An interface is even more abstract than an abstract class. An interface is basically a group of public methods, declared but not implemented. This group of methods defines how an object interacts with the outside world. Unlike abstract class, interface CANNOT contain instance or static variables, except for public static final variables (constants). Unlike abstract class, interface CANNOT contain implemented methods, i.e., all methods in an interface must be unimplemented. Interface CANNOT contain non-public methods. Another class can IMPLEMENT an interface. 7

Interface Example 8

When to use Abstract Class vs Interface Consider using Abstract Class if You want several closely-related classes to share the implementation of a common method. The classes extending this class share non-public methods or variables. You want to declare non-static or non-final variables. Consider using Interface if You expected that unrelated classes would implement this interface. e.g., the Comparable interface is implemented by many unrelated classes. You want to take advantage of multiple inheritance (a class can implement multiple interfaces). 9

NEXT TOPIC UML 10

UML Unified Modeling Language (UML) allows us to express the design of a program before writing any code. It is language-independent. An extremely expressive language. We ll use only a small part of the language, Class Diagrams, to represent basic OO design. 11

12

13

DEMO UML Visualization using ObjectAid http://www.objectaid.com/installation and many other UML tools are available for Eclipse. 14

15

NEXT TOPIC Graphical User Interface in Java 16

Creating GUI with Java.Swing and Java.awt Swing and AWT are collections of class for creating Graphical User Interfaces. They contains class for Windows, Buttons, Text Fields, Layouts, etc. Read some background info on Swing and AWT: http://edn.embarcadero.com/article/26970 17

Basic Workflow of Creating GUI All of the following is run in an Event-Dispatching Thread (EDT) launched by SwingUtilities. 1. Get the frame: Create a Window (JFrame) to hold the entire GUI. 2. Define how it looks: Create UI components (individual or grouped, with layout defined) and add them to the JFrame. 3. Define how it behaves: Attached handlers to UI components to handle events (button click, key press, etc). 4. Show it: Set size and location of the JFrame and make it visible. 18

DEMO: Hello World Example HelloWorldGUI.java 19

Different Layouts The layout defines the relative positions of the UI components. See this link to explore: https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html 20

DEMO: Layouts FlowFrame.java GridFrame.java ComplexFrame.java 21

ActionListener It is an interface for which you need implement the method actionperformed(); An ActionListener listens for events happens at where it is attached to, and performs the action defined in actionperformed() when an event is detected. For example, you can attach an ActionListener object to a JButton object in the UI, then the implementation of this listener s actionperformed() describes what happens whenever the button is pressed. 22

DEMO: ActionListner HiBye.java HiByeActionListener.java 23

DEMO: Key Press Event Handling KeypressDemo.java KeypressPanel.java 24

DEMO: Timer Events TimerDemo.java TickTimerHandler.java TockTimerHandler.java 25

Practice for Home Combine KeypressDemo and TimerDemo, so that the character moves automatically to the right by 5 pixels every second. 26

Another Example to Play with NumberGuessGame.java 27