1 Mouse Events See Figure See Example in Figure 11.28, 11.31
1 Digital Images Images are comprised of a two dimensional grid of pixels Each pixel (picture element) contains information about a color Many formats exist for storing images – Each has its own features – Examples: JPEG GIF PNG
1 Images in Java See Figure 21.1
1 Concurrency in Java Concurrency normally available in OS primitives – Most computers today allow more than one process or task running at any given time – Computers with more than one processor can actually run more than one process at a time Java provides built-in multithreading – Threads are to processes as applet are to applications – Multithreading improves the performance of some programs
1 Threads Thread states – Born state Thread was just created – Ready state Thread’s start method invoked Thread can now execute – Running state Thread is assigned a processor and running – Dead state Thread has completed or exited Eventually disposed of by system
1 A Thread's Life Ready Running BlockedSleepingWaiting start issue I/O request wait notify notifyAll timeout expires interrupt thread dispatch (assign a processor) quantum expiration yield sleep complete sleep interval expires interrupt Born enter synchronized statement I/O completes acquire lock interrupt When a thread completes (returns from its run method), it reaches the Dead state (shown here as the final state)
1 Thread Priorities and Thread Scheduling Java thread priority – Priority in range 1-10 Timeslicing – Each thread assigned time on the processor called a quantum – Keeps highest priority threads running
1 Thread priority scheduling example Priority 9 Priority 8 Priority 7 Priority 10 Priority 6 Priority 5 Priority 4 Priority 3 Priority 2 Priority 1 AB D C EF G H I JK Ready threads Thread.MIN_PRIORITY Thread.MAX_PRIORITY Thread.NORM_PRIORITY
1 Creating and Executing Threads Sleep state – Thread method sleep called – Thread sleeps for a set time interval then awakens Example – Figure 16.3: ThreadTester.java
1 Animating a Series of Images Threads are very useful for animation – Repeat Draw graphics Sleep Wake up Update – Loop structure handled at the thread level Example – Figure 21.2: LogoAnimator.java
1 Vectors Class java.util.Vector – Array-like data structures that can resize themselves dynamically – Contains a capacity – Grows by capacity increment if it requires additional space Example – Figure 21.1: VectorTest.java