H212 Introduction to Software Systems Honors

Similar documents
Graphical User Interfaces 2

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

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

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!

User interfaces and Swing

Graphical User Interfaces 2

Graphical User Interfaces 2

Graphic User Interfaces. - GUI concepts - Swing - AWT

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

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

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

Programmierpraktikum

Introduction to the JAVA UI classes Advanced HCI IAT351

Lecture 5: Java Graphics

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

GUI in Java TalentHome Solutions

Programming Languages and Techniques (CIS120)

SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

G51PRG: Introduction to Programming Second semester Applets and graphics

Lecture 9. Lecture

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

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

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

RAIK 183H Examination 2 Solution. November 11, 2013

Swing from A to Z Some Simple Components. Preface

RAIK 183H Examination 2 Solution. November 10, 2014

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

Graphical User Interfaces

FirstSwingFrame.java Page 1 of 1

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Using Several Components

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

AP Computer Science Unit 13. Still More Graphics and Animation.

Graphical User Interfaces. Comp 152

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

Computer Science 210: Data Structures. Intro to Java Graphics

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

Advanced Java Unit 6: Review of Graphics and Events

Graphical User Interfaces (GUIs)

MIT AITI Swing Event Model Lecture 17

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

Lecture 3: Java Graphics & Events

Final Examination Semester 2 / Year 2010

AP CS Unit 11: Graphics and Events

Window Interfaces Using Swing Objects

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

CS 251 Intermediate Programming GUIs: Components and Layout

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

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

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

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

Java Programming Lecture 6

Together, the appearance and how user interacts with the program are known as the program look and feel.

Final Examination Semester 2 / Year 2011

Window Interfaces Using Swing Objects

CS108, Stanford Handout #22. Thread 3 GUI

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

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

2IS45 Programming

AP CS Unit 12: Drawing and Mouse Events

Systems Programming Graphical User Interfaces

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Part 3: Graphical User Interface (GUI) & Java Applets

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

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

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill

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

COMP Assignment #10 (Due: Monday, March 11:30pm)

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

Final Examination Semester 2 / Year 2012

JAVA NOTES GRAPHICAL USER INTERFACES

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

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Object-oriented programming in Java (2)

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

Programming Language Concepts: Lecture 8

Class 16: The Swing Event Model

JLayeredPane. Depth Constants in JLayeredPane

INTRODUCTION TO (GUIS)

Agenda. Container and Component

Introduction. Introduction

CS 180 Fall 2006 Exam II

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

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

Java. GUI building with the AWT

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

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

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

THE UNIVERSITY OF AUCKLAND

BASICS OF GRAPHICAL APPS

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

COMPSCI 230. Software Design and Construction. Swing

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CSIS 10A Assignment 7 SOLUTIONS

Transcription:

Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14

Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9, listed at: http://www.cs.indiana.edu/classes/c212-dgerman/fall2015/lecturefourteen.html 1. Catching and Reporting Mouse Motion Events 2. Catching and Reporting Mouse Events 3. Catching and Reporting Action Events 4. Catching and Reporting Key(board) Events 5. Creating a JFrame, a JComponent and a Simple Graphics 6. Creating and Using Timers 7. Sorting an Array(List) of Objects 8. Throwing and Catching Exceptions 9. Creating and Using JButtons, JTextFields and JLabels 2/14

1. Catching and reporting mouse motion events We explained mouse events in Lecture 16, we mentioned two categories: mouse events mouse motion events Suppose we want to have a panel and to print the mouse position of we move the mouse. We need to implement: Frame Component We need a component object We have to add it to the frame Mouse listener We need to connect the components together. 3/14

Frame Remember: You cannot draw directly onto a frame! import javax.swing.*; public class myframe{ public static void main(string[] args) { JFrame a = new JFrame(); a.setvisible(true); a.setsize(400, 400); a.getcontentpane().add(new mycomponent ()); 4/14

JComponent JComponent class represents a blank component We have to modify the JComponent class and specify how the component should be painted. import javax.swing.*; import java.awt.*; public class mycomponent extends JComponent { Remember, paintcomponent is called: When the component is shown for the first time When the window is resized, When it is shown again after it was hidden, int x, y; public mycomponent() { Upon execution of repaint() this.addmousemotionlistener( new Helper(this) ); public void paintcomponent(graphics g) { g.drawstring("(" + this.x + ", " + this.y + ")", this.x, this.y); 5/14

Listener import java.awt.event.*; public class Helper implements MouseMotionListener { mycomponent myc; Helper(myComponent myc) { this.myc = myc; public void mousedragged(mouseevent e) { Remember: we have to implement all methods in the interface. public void mousemoved(mouseevent e) { this.myc.x = e.getx(); this.myc.y = e.gety(); this.myc.repaint(); Set x and y in mycomponent object to the current position of the mouse. Ask mycomponent object to the repaint itself. 6/14

Java puzzle public class Elementary { public static void main(string[] args) { System.out.println(12345 + 5432l); 7/14

We will implement a frame which will contain: button label 3. Catching and reporting action events Each time the button is pushed, the text on the label will be updated. Each container has its own layout manager, which determines how the components are laid out. By default, a JPanel uses a flow layout, which simply arranges its components from left to right and starts a new row when there is no more room in the current row. Another commonly used layout manager is the border layout, that groups components into five areas: center, north, west, south, and east. 8/14

import javax.swing.*; import java.awt.*; 3. Catching and reporting action events class One extends JFrame { private JButton b; private JLabel output; One() { createuserinterface(); Constructor public static void main(string[] args) { One one = new One(); one.setdefaultcloseoperation(jframe.exit_on_close); 9/14

private void createuserinterface() { Container c = getcontentpane(); c.setlayout(null); b = new JButton(); b.setbounds(20, 20, 120, 20); b.settext("push me!"); c.add(b); Add a button. output = new JLabel(); output.setbounds(50, 70, 220, 20); Add a label. output.settext("0 clicks so far. Push the button."); c.add(output); Two referee = new Two(output); b.addactionlistener(referee); When Action listener object is created, it is passed the reference to the label. Add listener for the button. setsize(400, 400); setvisible(true); Size of the frame. 10/14

Action listener import javax.swing.*; import java.awt.event.*; class Two implements ActionListener { int count = 0; JLabel label; Two(JLabel label) { this.label = label; public void actionperformed(actionevent e) { this.count += 1; System.out.println("Ouch: " + this.count); Constructor Action performed upon an event. this.label.settext(this.count + " click(s) so far and counting."); 11/14

import javax.swing.*; import java.awt.*; 4. Catching and reporting keyboard events class Three { public static void main(string[] args) { JFrame frame = new JFrame(); Container c = frame.getcontentpane(); c.setbackground(new Color(0.66f, 1.0f, 0.66f)); c.setlayout(null); JTextField t = new JTextField(); t.setbounds(10, 120, 70, 20); c.add(t); 12/14

4. Catching and reporting keyboard events KeyBroker k = new KeyBroker(); t.addkeylistener(k); JButton u = new JButton(); u.setbounds(100, 20, 90, 30); u.settext("erase"); c.add(u); ButtonBroker b = new ButtonBroker(t); u.addactionlistener(b); frame.setsize(300, 300); frame.setvisible(true); frame.setdefaultcloseoperation(jframe.exit_on_close); 13/14

4. Catching and reporting keyboard events import java.awt.event.*; class KeyBroker implements KeyListener { public void keypressed(keyevent e) { public void keyreleased(keyevent e) { public void keytyped(keyevent e) { System.out.println("Ouch!"); 14/14

import javax.swing.*; import java.awt.event.*; 4. Catching and reporting keyboard events class ButtonBroker implements ActionListener { JTextField t; ButtonBroker(JTextField t) { this.t = t; public void actionperformed(actionevent e) { System.out.println("Ha, ha!"); t.settext(""); 15/14