class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

Size: px
Start display at page:

Download "class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }"

Transcription

1 9.12) public interface Filter boolean accept(object x); Describes any class whose objects can measure other objects. public interface Measurer double measure(object anobject); This program tests the use of a Measurer and a Filter. public class DataSetTester class BankMeasurer implements Measurer public double measure(object anobject) BankAccount ba = (BankAccount) anobject; return ba.getbalance(); class BankFilter implements Filter public boolean accept(object x) BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; Measurer m = new BankMeasurer(); Filter f = new BankFilter(); DataSet data = new DataSet(m, f); data.add(new BankAccount(1)); data.add(new BankAccount(100));

2 data.add(new BankAccount(2000)); data.add(new BankAccount(950)); data.add(new BankAccount(4000)); System.out.println("Average balance: " + data.getaverage()); System.out.println("Expected: 3000"); BankAccount b = (BankAccount) data.getmaximum(); double balance = b.getbalance(); System.out.println("Highest balance: " + balance); System.out.println("Expected: 4000"); 9.21) import java.awt.event.actionevent; import java.awt.event.actionlistener; An action listener that prints a message. public class ClickListener implements ActionListener private int count; public ClickListener() count = 0; public void actionperformed(actionevent event) count++; if (count == 1) System.out.println("I was clicked 1 time!"); else System.out.println("I was clicked " + count + " times!"); import java.awt.event.actionlistener; import javax.swing.jbutton;

3 import javax.swing.jframe; import javax.swing.jpanel; This program demonstrates how to install an action listener. public class ButtonViewer private static final int FRAME_WIDTH = 100; private static final int FRAME_HEIGHT = 100; JFrame frame = new JFrame(); JPanel panel = new JPanel(); JButton button = new JButton("Click me!"); panel.add(button); JButton button2 = new JButton("Click me too!"); panel.add(button2); frame.add(panel); ActionListener listener = new ClickListener(); button.addactionlistener(listener); ActionListener listener2 = new ClickListener(); button2.addactionlistener(listener2); frame.setsize(frame_width, FRAME_HEIGHT); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); 9.28) import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.joptionpane; import javax.swing.timer; import java.util.date;

4 Displays the current time once every second. public class TimePrinter class CurrentTime implements ActionListener public void actionperformed(actionevent event) Date now = new Date(); System.out.println(now); CurrentTime listener = new CurrentTime(); ticks final int DELAY = 1000; // milliseconds between timer Timer t = new Timer(DELAY, listener); t.start(); JOptionPane.showMessageDialog(null, "Quit?"); System.exit(0); 9.34) Allows the user to specify a circle by typing the radius in a text field and then clicking on the center. public class CircleDrawerFrame extends JFrame private CircleDrawerComponent component; private static final int FRAME_WIDTH = 400; private static final int FRAME_HEIGHT = 400; public int radius;

5 public CircleDrawerFrame() component = new CircleDrawerComponent(); component.setpreferredsize(new Dimension(400,350)); // add mouse press listener class MousePressListener implements MouseListener public void mousepressed(mouseevent event) int x = event.getx(); int y = event.gety(); radius"); String ansradius = JOptionPane.showInputDialog("Enter radius = Integer.parseInt(ansRadius); component.setpositionandsize(x, y, radius); // do-nothing methods public void mousereleased(mouseevent event) public void mouseclicked(mouseevent event) public void mouseentered(mouseevent event) public void mouseexited(mouseevent event) MouseListener listener = new MousePressListener(); component.addmouselistener(listener); setsize(frame_width, FRAME_HEIGHT); add(component); public class CircleDrawerComponent extends JComponent private Ellipse2D.Double circle; private int x; private int y; private int radius; public CircleDrawerComponent() x = 0;

6 y = 0; radius = 0; circle = null; public void setpositionandsize(int ax, int ay, int aradius) x = ax; y = ay; radius = aradius; // the circle that the paintcomponent method draws circle = new Ellipse2D.Double(x - radius, y - radius, radius * 2, radius * 2); repaint(); public void paintcomponent(graphics g) if (circle == null) return; Graphics2D g2 = (Graphics2D) g; g2.draw(circle); import javax.swing.jframe; Allows the user to specify a circle by typing the radius in a text field and then clicking on the center. public class CircleDrawer JFrame frame = new CircleDrawerFrame(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.settitle("circledrawer"); frame.setvisible(true);

Chapter Nine: Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved.

Chapter Nine: Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Chapter Nine: Interfaces and Polymorphism Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how

More information

3/7/2012. Chapter Nine: Interfaces and Polymorphism. Chapter Goals

3/7/2012. Chapter Nine: Interfaces and Polymorphism. Chapter Goals Chapter Nine: Interfaces and Polymorphism Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how

More information

10/27/2011. Chapter Goals

10/27/2011. Chapter Goals Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how interfaces can be used to decouple classes

More information

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

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners GUI (Graphic User Interface) Programming Part 2 (Chapter 8) Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the

More information

Chapter 9 Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Chapter 9 Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 9 Interfaces and Polymorphism Chapter Goals To be able to declare and use interface types To understand the concept of polymorphism To appreciate how interfaces can be used to decouple classes

More information

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

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

More information

Chapter 9. Interfaces and Polymorphism. Chapter Goals. Chapter Goals. Using Interfaces for Code Reuse. Using Interfaces for Code Reuse

Chapter 9. Interfaces and Polymorphism. Chapter Goals. Chapter Goals. Using Interfaces for Code Reuse. Using Interfaces for Code Reuse Chapter 9 Interfaces and Polymorphism Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how interfaces

More information

Interfaces and Polymorphism Advanced Programming

Interfaces and Polymorphism Advanced Programming Interfaces and Polymorphism Advanced Programming ICOM 4015 Lecture 10 Reading: Java Concepts Chapter 11 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about interfaces To

More information

public DataSet(Measurer ameasurer) { sum = 0; count = 0; minimum = null; maximum = null; measurer = ameasurer; }

public DataSet(Measurer ameasurer) { sum = 0; count = 0; minimum = null; maximum = null; measurer = ameasurer; } 9.5) Computes the average of a set of data values. public class DataSet private double sum; private Object minimum; private Object maximum; private int count; private Measurer measurer; public DataSet(Measurer

More information

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN CSSE 220 Event Based Programming Check out EventBasedProgramming from SVN Interfaces are contracts Interfaces - Review Any class that implements an interface MUST provide an implementation for all methods

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming 1. Event handling in Java 2. Introduction to Java Graphics OOP9 - M. Joldoş - T.U. Cluj 1 Reminder: What is a callback? Callback is a scheme used in event-driven programs where

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

Submit your solution to the Desire2Learn drop box. You may submit as many versions as you like the last one will be graded.

Submit your solution to the Desire2Learn drop box. You may submit as many versions as you like the last one will be graded. CS46A Exam 2 Exam Rules You may use any books, notes, files, web sites of your choice, except as noted below. It is a good idea to compile and run your programs if you have the time to do it. You may NOT

More information

Check out ThreadsIntro project from SVN. Threads and Animation

Check out ThreadsIntro project from SVN. Threads and Animation Check out ThreadsIntro project from SVN Threads and Animation Often we want our program to do multiple (semi) independent tasks at the same time Each thread of execution can be assigned to a different

More information

Chapter 10 Inheritance. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Chapter 10 Inheritance. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 10 Inheritance Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

More information

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

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

Course: CMPT 101/104 E.100 Thursday, November 23, 2000 Course: CMPT 101/104 E.100 Thursday, November 23, 2000 Lecture Overview: Week 12 Announcements Assignment 6 Expectations Understand Events and the Java Event Model Event Handlers Get mouse and text input

More information

Programming Graphics (P1 2006/2007)

Programming Graphics (P1 2006/2007) Programming Graphics (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To be

More information

CIS 120 Final Exam 16 December Name (printed): Pennkey (login id):

CIS 120 Final Exam 16 December Name (printed): Pennkey (login id): CIS 120 Final Exam 16 December 2015 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing

More information

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

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build

More information

Handling Mouse and Keyboard Events

Handling Mouse and Keyboard Events Handling Mouse and Keyboard Events 605.481 1 Java Event Delegation Model EventListener handleevent(eventobject handleevent(eventobject e); e); EventListenerObject source.addlistener(this);

More information

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

APPENDIX. public void cekroot() { System.out.println(nilai root : +root.data); } APPENDIX CLASS NODE AS TREE OBJECT public class Node public int data; public Node left; public Node right; public Node parent; public Node(int i) data=i; PROCEDURE BUILDING TREE public class Tree public

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 2011 Extending JFrame Dialog boxes Overview Ge

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 32 April 9, 2018 Swing I: Drawing and Event Handling Chapter 29 HW8: Spellchecker Available on the web site Due: Tuesday! Announcements Parsing, working

More information

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

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors 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,

More information

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

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Lab 15 Name: Checked: Objectives: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Files: http://www.csc.villanova.edu/~map/1051/chap04/smilingface.java http://www.csc.villanova.edu/~map/1051/chap04/smilingfacepanel.java

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 November 30, 2018 Mushroom of Doom Model / View / Controller Chapter 31 Announcements Game Project Complete Code Due: Monday, December 10th NO LATE

More information

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

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping. HW#1: Pencil Me In Status!? CS193J: Programming in Java Summer Quarter 2003 Lecture 6 Inner Classes, Listeners, Repaint Manu Kumar sneaker@stanford.edu How was Homework #1? Comments please? SITN students

More information

3/7/2012. Chapter Ten: Inheritance. Chapter Goals

3/7/2012. Chapter Ten: Inheritance. Chapter Goals Chapter Ten: Inheritance Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for

More information

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

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 15, 2013 Swing III: OO Design, Mouse InteracGon Announcements HW10: Game Project is out, due Tuesday, April 23 rd at midnight If you want

More information

// autor igre Ivan Programerska sekcija package mine;

// autor igre Ivan Programerska sekcija package mine; // autor igre Ivan Bauk @ Programerska sekcija package mine; import java.awt.color; import java.awt.flowlayout; import java.awt.gridlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener;

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 13, 2017 Model / View / Controller Chapter 31 How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal

More information

COMP 102: Test 2 Model Solutions

COMP 102: Test 2 Model Solutions Family Name:.......................... Other Names:.......................... ID Number:............................ Instructions Time allowed: 45 minutes There are 45 marks in total. Answer all the questions.

More information

Sample Solution A10 R6.2 R6.3 R6.5. for (i = 10; i >= 0; i++)... never ends. for (i = -10; i <= 10; i = i + 3)... 6 times

Sample Solution A10 R6.2 R6.3 R6.5. for (i = 10; i >= 0; i++)... never ends. for (i = -10; i <= 10; i = i + 3)... 6 times Sample Solution A10 R6.2 0000000000 0123456789 0246802468 0369258147 0482604826 0505050505 0628406284 0741852963 0864208642 0987654321 R6.3 for (i = 10; i >= 0; i++)... never ends for (i = -10; i

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test.

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 21, 2014 Swing III: Paint demo, Mouse InteracFon HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your

More information

P 6.3) import java.util.scanner;

P 6.3) import java.util.scanner; P 6.3) import java.util.scanner; public class CurrencyConverter public static void main (String[] args) Scanner in = new Scanner(System.in); System.out.print("How many euros is one dollar: "); double rate

More information

SampleApp.java. Page 1

SampleApp.java. Page 1 SampleApp.java 1 package msoe.se2030.sequence; 2 3 /** 4 * This app creates a UI and processes data 5 * @author hornick 6 */ 7 public class SampleApp { 8 private UserInterface ui; // the UI for this program

More information

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

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Events and Listeners CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor:

More information

Sample Solution Assignment 5. Question R3.1

Sample Solution Assignment 5. Question R3.1 Sample Solution Assignment 5 Question R3.1 The interface of a class is the part that the user interacts with, not necessarily knowing how it works. An implementation of is the creation of this interface.

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

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

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms. Java GUI Windows Events Drawing 1 Java GUI Toolkits Toolkit AWT Description Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

More information

CHAPTER 9 INTERFACES AND POLYMORPHISM

CHAPTER 9 INTERFACES AND POLYMORPHISM CHAPTER 9 INTERFACES AND POLYMORPHISM Using Interfaces for Code Reuse Use interface types to make code more reusable In Chapter 6, we created a DataSet to find the average and maximum of a set of values

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2009 FINAL EXAMINATION 7pm to 10pm, 18 APRIL 2009, Dunning Hall Instructor: Alan McLeod If the

More information

FirstSwingFrame.java Page 1 of 1

FirstSwingFrame.java Page 1 of 1 FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import

More information

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! ADVANCED OBJECT-ORIENTATION 2 Object-Oriented Design classes often do not exist in isolation from each

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #15: October 21, 2015 1/34 Generic classes and types Generic programming is the creation of programming constructs that can be usedwith many different types.

More information

ว ฒนพงศ ส ทธภ กด Java Programming ( )

ว ฒนพงศ ส ทธภ กด Java Programming ( ) ว ฒนพงศ ส ทธภ กด Java Programming (254372 ) Basic GUI - Frame(new Windows) - Component - popup - addcomponentlistener - addmouselistener - Eclipse plugin for gui(windows Builder) import javax.swing.jframe;

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded

More information

Graphical User Interface

Graphical User Interface Lecture 10 Graphical User Interface An introduction Sahand Sadjadee sahand.sadjadee@liu.se Programming Fundamentals 725G61 http://www.ida.liu.se/~725g61/ Department of Computer and Information Science

More information

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam Dartmouth College Computer Science 10, Fall 2015 Midterm Exam 6.00-9.00pm, Monday, October 19, 2015 105 Dartmouth Hall Professor Prasad Jayanti Print your name: Print your section leader name: If you need

More information

Section Basic graphics

Section Basic graphics Chapter 16 - GUI Section 16.1 - Basic graphics Java supports a set of objects for developing graphical applications. A graphical application is a program that displays drawings and other graphical objects.

More information

javax.swing Swing Timer

javax.swing Swing Timer 27 javax.swing Swing SwingUtilities SwingConstants Timer TooltipManager JToolTip 649 650 Swing CellRendererPane Renderer GrayFilter EventListenerList KeyStroke MouseInputAdapter Swing- PropertyChangeSupport

More information

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets Advanced Swing Outline More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets Using menus Frame menus add a menu bar to the frame (JMenuBar) add menus to

More information

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 {

import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 { import java.awt.color; import java.awt.flowlayout; import java.awt.font; import java.awt.gridlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jbutton;

More information

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

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2 1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring 2010 - Quiz 2 Name: MIT Email: TA: Section: You have 80 minutes to complete this exam. For coding questions, you do not need

More information

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI 51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface

More information

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Exam: Applet, Graphics, Events: Mouse, Key, and Focus Exam: Applet, Graphics, Events: Mouse, Key, and Focus Name Period A. Vocabulary: Complete the Answer(s) Column. Avoid ambiguous terms such as class, object, component, and container. Term(s) Question(s)

More information

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

More information

AP CS Unit 12: Drawing and Mouse Events

AP CS Unit 12: Drawing and Mouse Events AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.

More information

EXAMINATIONS 2010 END-OF-YEAR COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

EXAMINATIONS 2010 END-OF-YEAR COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2010 END-OF-YEAR COMP 102 INTRODUCTION TO

More information

AnimatedImage.java. Page 1

AnimatedImage.java. Page 1 1 import javax.swing.japplet; 2 import javax.swing.jbutton; 3 import javax.swing.jpanel; 4 import javax.swing.jcombobox; 5 import javax.swing.jlabel; 6 import javax.swing.imageicon; 7 import javax.swing.swingutilities;

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber Portion of the Java class hierarchy that include basic graphics classes and Java 2D API classes and interfaces. java.lang.object Java.awt.Color Java.awt.Component Java.awt.Container

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

More information

Outline. Anonymous Classes. Annoucements. CS1007: Object Oriented Design and Programming in Java

Outline. Anonymous Classes. Annoucements. CS1007: Object Oriented Design and Programming in Java Outline CS1007: Object Oriented Design and Programming in Java Lecture #9 Oct 6 Shlomo Hershkop shlomo@cs.columbia.edu Polymorphism Basic graphics Layout managers Customization Reading: 4.5-4.8, 4.9 1

More information

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 2 2 Develop the layout of those elements 3 3 Add listeners to the elements 9 4 Implement custom drawing 12 1 The StringArt Program To illustrate

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 3 2 Develop the layout of those elements 4 3 Add listeners to the elements 12 4 Implement custom drawing 15 1 The StringArt Program To illustrate

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CMPE212, FALL TERM, 2012 FINAL EXAMINATION 18 December 2012, 2pm Instructor: Alan McLeod If the instructor is unavailable

More information

Workbook 7. Remember to check the course website regularly for announcements and errata:

Workbook 7. Remember to check the course website regularly for announcements and errata: Introduction Workbook 7 Last week you built your own graphical interface with Java Swing in order to make your program more accessible to other users. Unfortunately, whilst your interface looked pretty,

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

CompSci 230 S Programming Techniques. Basic GUI Components

CompSci 230 S Programming Techniques. Basic GUI Components CompSci 230 S1 2017 Programming Techniques Basic GUI Components Agenda Agenda Basic GUI Programming Concepts Graphical User Interface (GUI) Simple GUI-based Input/Output JFrame, JPanel & JLabel Using Layout

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2009 FINAL EXAMINATION 7pm to 10pm, 18 APRIL 2009, Dunning Hall Instructor: Alan McLeod

More information

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

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

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

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1 Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes

More information

PIC 20A GUI with swing

PIC 20A GUI with swing PIC 20A GUI with swing Ernest Ryu UCLA Mathematics Last edited: November 22, 2017 Hello swing Let s create a JFrame. import javax. swing.*; public class Test { public static void main ( String [] args

More information

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t;

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t; 1 AppBisect > PrBisect > class Punct public class Punct { double x,y; public Punct(double x, double y) { this.x = x; this.y = y; public void setx(double x) { this.x = x; public double getx() { return x;

More information

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

JComponent. JPanel. JFrame. JFrame JDialog, JOptionPane. JPanel. JPanel JComponent JPanel JPanel JFrameJDialog, JOptionPane JFrame JPanel Myclass SomeInterface SomeInterface anobject = new SomeInterface () { public void interfacefunc() { System.out.println("Some

More information

UCLA PIC 20A Java Programming

UCLA PIC 20A Java Programming UCLA PIC 20A Java Programming Instructor: Ivo Dinov, Asst. Prof. In Statistics, Neurology and Program in Computing Teaching Assistant: Yon Seo Kim, PIC University of California, Los Angeles, Summer 2002

More information

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

TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill dewan@cs.unc.edu Code available at: https://github.com/pdewan/colabteaching PRE-REQUISITES Model-

More information

Object Orientated Programming in Java. Benjamin Kenwright

Object Orientated Programming in Java. Benjamin Kenwright Graphics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Graphical Principals JFrame Window (Popup Windows) Extending JFrame Drawing from paintcomponent Drawing images/text/graphics

More information

CS 2113 Software Engineering

CS 2113 Software Engineering CS 2113 Software Engineering Java 5 - GUIs Import the code to intellij https://github.com/cs2113f18/template-j-5.git Professor Tim Wood - The George Washington University Class Hierarchies Abstract Classes

More information

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

More information

Java for Interfaces and Networks (DT3010, HT10)

Java for Interfaces and Networks (DT3010, HT10) Java for Interfaces and Networks (DT3010, HT10) Mouse Events, Timers, Serialization Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces

More information

COMP16121 Sample Code Lecture 1

COMP16121 Sample Code Lecture 1 COMP16121 Sample Code Lecture 1 Sean Bechhofer, University of Manchester, Manchester, UK sean.bechhofer@manchester.ac.uk 1 SimpleFrame 1 import javax.swing.jframe; 2 3 public class SimpleFrame { 4 5 /*

More information

Advanced Java Unit 6: Review of Graphics and Events

Advanced Java Unit 6: Review of Graphics and Events Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow

More information

Building Java Programs Bonus Slides

Building Java Programs Bonus Slides Building Java Programs Bonus Slides Graphical User Interfaces Copyright (c) Pearson 2013. All rights reserved. Graphical input and output with JOptionPane JOptionPane An option pane is a simple dialog

More information