A cannon game ?. Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate:

Slides:



Advertisements
Similar presentations
Graphic User Interfaces Layout Managers Event Handling.
Advertisements

Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
James Tam An introduction into HCI: Task-Centered System Design An Introduction To Graphical User Interfaces The event-driven model Building a simple.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Java Programming Chapter 10 Graphical User Interfaces.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Session 9 CannonWorld, Event-driven Programming, and Border Layout.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Session 10 CannonGame and Event-driven Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
2-Dec-15 Inner Classes. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Object Oriented Programming.  Interface  Event Handling.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Introduction to Applets Chapter 21. Applets An applet is a Java application that is intended to be invoked and executed through a Web browser. Click Here.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Object Oriented Programming in Java Habib Rostami Lecture 10.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
Block 1 Unit 2 Basic Constructs in Java. Objectives create a simple object using a constructor; create and display a window frame on your computer screen;
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Inner Classes.
CSC 205 Programming II Lecture 5 AWT - I.
Topic: Inner Classes Course : JAVA PROGRAMMING Paper Code: ETCS-307 Faculty : Dr. Prabhjot Kaur Reader, Dept. of IT 1.
CompSci 230 S Programming Techniques
Inner Classes 27-Dec-17.
Graphical User Interfaces -- GUIs
“Form Ever Follows Function” Louis Henri Sullivan
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Inner Classes 11/14/ Dec-04 inner_classes.ppt.
Inner Classes 29-Nov-18.
Events, Event Handlers, and Threads
Constructors, GUI’s(Using Swing) and ActionListner
Border Layout, using Panels, Introduction to PinBallGame
Chapter 5 Processing Input with Applets
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 1-May-19.
Inner Classes 11-May-19.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Inner Classes 18-May-19.
Session 29 Introducing CannonWorld (Event-driven Programming)
Inner Classes.
Inner Classes 25-Oct-19.
Presentation transcript:

A cannon game ?

Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate: public int dy(int y) { return FrameHeight-y;} x y 0,0 Java: usually: 0,0 y x

Gravity public class CannonBall extends Ball { public CannonBall(int sx, int sy, int r, double dx, double dy) { super(sx,sy,sr); setMotion(dx,dy); } public static final double GravityEffect = 0.3; public void move() { dy = dy + GravityEffect; super.move(); }} Can invoke overridden superclass method using super.methodname (cf. constructor)

Integers versus ints Values of primitive data types (ints, double, …) are not instances of a class Wrapper classes provide useful functionality: Integer, Double, … Both regular and static methods: Integer i1 = Integer.valueOf(args[0]); int i2 = i1.intValue();

Version 2: User interaction Button: start/terminate, turn on/off something Slider: one way of selecting a quantity Need to import both java.awt.* as well as java.awt.event.*

Inner classes Can define a class inside another class: public class CannonWorld extends Frame { … private class FireButtonListener implements ActionListener {..} ….} Inner classes may access all their surrounding context, including private data members and methods (see ScrollBarListener modifying private data members angle and message)

Interfaces An interface specifies method headers only (and maybe static data members) interface ActionListener { public void actionPerformed(ActionEvent); } If a class implement an interface: Class FireButtonListener implements ActionListener {..} then it MUST provide definitions for all methods of that interface! A class can implement multiple interfaces (but it can only extend one class)

The Java event model Event: action like “click button”, … Program response: perform some action “event-driven” interface Java: “listener” object waits for events Button fire = new Button(“Fire”); fire.addActionListener(new FireButtonListener); On button-press: call actionPerformed method, we MUST implement this method

Window layout Layout manager: controls the layout of components in a window, default is BorderLayout, can specify: “North” = top “South” = bottom “East” = right “West” = left E.g.: add(“East”,slider);

OO Progam = team of classes CannonWorld extends Frame CannonBall extends Ball Integer: utility, e.g. String-to-int conversion GUI, event classes: Button, ScrollBar FireButtonListener, ScrollBarListener ActionEvent, AdjustmentEvent BorderLayout ALL WITHIN THREE PAGES OF CODE

Summary Integer: useful wrapper class CannonBall: inherits from Ball Pseudo-variable super: access both Constructors of the superclass (overridden) Methods of the superclass Inner classes: full access to surrounding context Interface: promise implement methods Event model: listeners GUI utilities: Button,Slider,BorderLayout