Expanding the PinBallGame

Slides:



Advertisements
Similar presentations
13/04/2015Client-server Programming1 Block 6: Threads 1 Jin Sa.
Advertisements

Multithreaded Programs in Java. Tasks and Threads A task is an abstraction of a series of steps – Might be done in a separate thread – Java libraries.
ABSTRACT CLASSES AND INTERFACES. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method without.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
AbstractClassesInterfacesPolymorphism1 Abstract Classes, Interfaces, Polymorphism Barb Ericson Georgia Tech April 2010.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Cosc 4755 Phone programming: GUI Concepts & Threads.
OOP&M - theory lectures1 OOP&M – and there it was an eighth day “I f you know what I know, what am I doing here? ” - Aristoteles -
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
OOP Week 3 1 Object Oriented Programming in Java Monday, Week 3 Interface PinBallTarget OOP Concepts Last Week’s Assignment Arrays Collection Class --
Abstract Classes and Interfaces
Programming Task: Task 1 Controlled Assessment Practice.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
M1G Introduction to Programming 2 4. Enhancing a class:Room.
Session 12 Introduction to PinBallGame (Chaper 7).
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
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,
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Session 21 Chapter 10: Mechanisms for Software Reuse.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Session 15 Chapter 8: Understanding Inheritance. Lab Exercise Solution Recall that we needed to know if a mousePress occurred on a target. We tried to.
1 Web Based Programming Section 8 James King 12 August 2003.
Threading Eriq Muhammad Adams J
Chapter 7: Pinball Game Construction Kit. Vectors Example of a “collection class” Must “import java.util.Vector” More flexible than arrays: will grow.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Session 19 Chapter 10 – Mechanisms for Software Reuse.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Session 18 Chapter 8: Understanding Inheritance. Recall Exercise 2 From Tuesday It’s very annoying to move a target from the pallet and drop it in the.
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Session 13 Pinball Game Construction Kit (Version 3):
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Session 25 Test 2 Review. Test 2 Details Tuesday, November 22 in class –(Anybody planning on taking it on Friday?) Closed book Closed notes, except for.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Multi-Threading in Java
A Introduction to Computing II Lecture 4: Visual Programming A Case Study of OOP Fall Session 2000.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Java exercise review Lesson 26: Exercise 4. Exercise #4 – a sample solution 1.Write the psudocode and the deployment diagram for what you are planning.
Object Oriented Programming Lecture 3: Things OO.
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Introducing, the JFrame Gives us a work area beside System.out.println.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Java Thread Programming
Animate objects and threads
Inheritance and Polymorphism
Chapter 19 Java Never Ends
Your First Java Application
slides created by Alyssa Harding
Java Concurrency 17-Jan-19.
Focus of the Course Object-Oriented Software Development
Border Layout, using Panels, Introduction to PinBallGame
Java Concurrency.
Programming with inheritance Based on slides by Alyssa Harding
Java Concurrency.
Representation and Management of Data on the Internet
Java Concurrency 29-May-19.
Threads and concurrency / Safety
Presentation transcript:

Expanding the PinBallGame Session 35 Expanding the PinBallGame

The next slides are all review from Friday

PinBall Contruction Kit Version 2

Questions How is the “black box” in the PinBallGame drawn? What is the difference between the items outside the box of the game window and the items inside the box?   What messages can we send to a Peg, and where is each behavior defined? What is the purpose of the PinBallTarget interface? Why can’t we do without it?

PinBallTarget Interface interface PinBallTarget { public boolean intersects (Ball aBall); public void moveTo (int x, int y); public void paint (Graphics g); public void hitBy (Ball aBall); } Why use an interface? we want to process targets uniformly, e.g., check if a ball hit it the interface makes them the same “type” for storage in a Vector

Hole target structurally similar to a ball behavioral round like a ball has a location on the frame like a ball behavioral it must adhere to the interface class Hole extends Ball implements PinBallTarget Inherits moveTo and paint, but supplies intersects and hitBy

More on Threads We can think of separate threads as separate programs running concurrently. They don’t literally run at the same time (unless you have a machine with more than one CPU). Instead, one thread gets the CPU for a while, then it gets put on hold while another thread gets the CPU, and so on. When separate threads are running, sometimes we need to worry about two threads taking actions that conflict with one another. We can use the keyword synchronized to have the JVM help maintain order.

A Problem Caused by Separate Threads of Control

More on Threads Example: The second version of the pin ball game keeps track of the score the user earns for hitting targets in the field of play. It keeps track of the score in an instance variable named score: private int score = 0; When a pin ball strikes a target, the target tells the pin ball game to add its point total to the instance variable by sending an addScore message: public void addScore( int value ) { score = score + value; scoreLabel.setText( "score = " + score ); }

A Problem Caused by Separate Threads of Control

The solution synchronized public void addScore( int value ) { score = score + value; scoreLabel.setText( "score = " + score ); } The keyword synchronized is used to ask Java to guarantee that only one thread at a time can be executing the addScore() method.

What improvements would you like to make?