Starts to load image Delay on network Load some more of the image Time for some word processing Thread 2 Thread 1 Figure 15.1 Two threads sharing the processor.

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

Using Thread for Animation. Threads When we are doing multiple things at once we say we are multitasking Computers multitask when they run several programs.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
CompSci Today’s topics Java Recursion in Graphics Writing a Class Simple Animation Upcoming Simulation Reading Great Ideas, Chapters 5.
Java Applets- Using SwingWorker Dave Price and Chris Loftus Computer Science Department University of Wales, Aberystwyth.
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
JFrame JComponent JFrame JComponent JFrame JComponent.
Jim Priest, Peter Lundgren, Russell Bennett. Background info  A sequence of fames  You have some experience already  Used for some GUI’s and Games.
Albert Johnson Molly Richardson Andrew Kruth.  Threads Runnable interface sleep()  GUIs repaint() paintComponent()
(c) 2006 E.S.Boese All Rights Reserved. Threads and Timers Chapter 19 - Student.
Event Handling Events and Listeners Timers and Animation.
Public class MyThread1 extends Thread { public void start() { } public void run() { System.out.print(“Hello \n”) } public class MyThread2 extends Thread.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
24-Jun-15 Simple Animation. 2 The bouncing ball The “bouncing ball” is to animation what “Hello world” is to programming With a single Thread, we can.
Lecture 17: Animation Yoni Fridman 7/27/01 7/27/01.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
P247. Figure 9-1 p248 Figure 9-2 p251 p251 Figure 9-3 p253.
Java Threads CS Introduction to Operating Systems.
Inner Classes. Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class Inner classes.
Animation To animate our programs, that is, to have real time interactions where objects move on the screen, we want to call repaint( ) every few milliseconds.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
Java: Animation Chris North cs3724: HCI. Animation? Changing graphics over time Examples: cartoons Clippy, agents/assistants Hour glass Save dohicky Progress.
EE2E1. JAVA Programming Lecture 8 Multi-threading.
Concurrency in First Year Judith Bishop University of Pretoria South Africa
Chapter 15 Multithreading F Threads Concept  Creating Threads by Extending the Thread class  Creating Threads by Implementing the Runnable Interface.
Threads and Multimedia Animation, Images, Sound. Animation nAnimation, displaying a sequence of frames to create the illusion of motion, is a typical.
(c) 2008 E.S.Boese All Rights Reserved. Threads and Media Chapter 8 - Lecture Slides 1.
Programming for WWW (ICE 1338) Lecture #7 Lecture #7 July 14, 2004 In-Young Ko iko.AT. icu.ac.kr Information and Communications University (ICU) iko.AT.
CS12420 – Swing and threads Lynda Thomas
BI-SW Training day Outline What is the EDT? Why should I care about it? How do I treat GUI objects properly? SwingWorker and its advantages.
1 Web Based Programming Section 8 James King 12 August 2003.
1 Learning objectives By the end of this chapter you should be able to:  explain how concurrency is achieved by means of time-slicing;  distinguish between.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Concurrent Programming and Threads Threads Blocking a User Interface.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
Java Inner Classes. Interfaces interface KeyListener { public void keyPressed(KeyEvent e); public void keyReleased(KeyEvent e); public void keyTyped(KeyEvent.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Threads II IS Outline  Quiz  Thread review  Stopping a thread  java.util.Timer  Swing threads javax.swing.Timer  ProgressMonitor.
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
17/3/00SEM107 © Kamin & Reddy Class 13 - Animation 1 Class 13 - Animation r Summary of loops m while-do m for m do-while r while loop examples r for loop.
Practical Session 10: Animation. Animation kinds There are three basic kinds of animation: 1. Moving object 2. Changing pictures 3. Combination of 1 and.
1 Mouse Events See Figure See Example in Figure 11.28,
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה. בשבוע שעבר  paint  Graphics  repaint.
Threads and Multithreading. Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three general approaches:
1NetBeans Tutorial Using the “Properties” menu, name the List “List1” and the button “Button1”. NetBeans Tutorial6.
Java Applets Adding Animation. Import Files You still need to include the same files: –import java.applet.*; –import java.awt.*;
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Chapter 11: Threaded Programs Situations where the program is following multiple execution paths (how to stop one?) Thread: a line of execution Thread.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
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;
Image from
» The thief and house program we used last time is refactored to follow the MVC pattern » Now it consists of four parts: ˃AScene (model) ˃AThiefController.
Tim Anderson, Daniel Lehman, Cort Pugh, Alia Robinson
Modular Event Handling
Chapter 13: Multithreading
The Bouncing Ball Problem (Independent Threads)
Animating with EventTimer
Lecture 9 Object Oriented Programming Using Java
Multimedia in Java Multimedia combines graphics, animation and sound
Threading Issues A user presses a button on a web browser that stops a web page from loading any further: The thread accepting the user stop button press.
Tips Need to Consider When Organizing a College Event
Threads II IS
Inner Classes 11/14/ Dec-04 inner_classes.ppt.
ماجستير إدارة المعارض من بريطانيا
مديريت موثر جلسات Running a Meeting that Works
Java Inner Classes.
Java Thread.
Threads.
Inner Classes.
Presentation transcript:

Starts to load image Delay on network Load some more of the image Time for some word processing Thread 2 Thread 1 Figure 15.1 Two threads sharing the processor

Figure 15.2 Threads of Example 15.1 sleeping and waking up Main Bonnie Clyde Time

public void actionPerformed (ActionEvent event) { x += 9; y += 9; repaint(); } Figure 15.3 Handling a button press to move a ball

public void actionPerformed (ActionEvent event) { for (int i = 0; i < 10; i++) { x += 9; y += 9; repaint(); } Figure 15.4 An attempt to move the ball 10 times with one button press

public void run () { for (int i = 0; i < 10; i++) { x+= 9; y += 9; repaint(); try { Thread.sleep(300); } catch(InterruptedException e) { e.printStackTrace(); } Figure 15.6 The run method of a thread for an animation

Figure The Towers of Hanoi puzzle