EventsAndThreads

EventsAndThreads - Graphic Interface Programming II Events...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
IT Uppsala universitet Graphic Interface Programming II Events and Threads
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UU/IT 3/23/10 | #2 @ UU/IT Animation Animation adds to user experience Done right, it enhances the User Interface Done wrong, it distracts and irritates
Background image of page 2
UU/IT 3/23/10 | #3 @ UU/IT Active Objects Javax.swing.Timer Timer t = new Timer(interval, listener); Interval is in milliseconds Listener is an object listening to the events ActionListener Don’t confuse with java.util.Timer (!)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UU/IT 3/23/10 | #4 @ UU/IT Concurrency
Background image of page 4
UU/IT 3/23/10 | #5 @ UU/IT Synchronization Making sure that some events can’t collide Preventing deadlocks Preventing data corruption EXAMPLES
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UU/IT 3/23/10 | #6 @ UU/IT Threads in Swing Swing is NOT thread-safe! Using concurrency works most of the time, but… …might cause unpredictable errors… …that are difficult to reproduce…. Event dispatch thread
Background image of page 6
UU/IT 3/23/10 | #7 @ UU/IT Threads Definition: A thread is a single sequential flow of control within a program Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed by the event-dispatching thread.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UU/IT 3/23/10 | #8 @ UU/IT Event Dispatch Thread
Background image of page 8
UU/IT 3/23/10 | #9 @ UU/IT EDT A series of ”small” tasks in a queue e.g., invocations of event-handling methods scheduled from application code (invokeLater) javax.swing.Timer Ensures that the tasks are performed in a ”safe” manner
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UU/IT 3/23/10 | #10 @ UU/IT Implications when using Swing The most important thing is to make sure that the Swing thread won't hang when time- consuming operations are performed. It is also important that calls to Swing always are made from Swing's event- thread.
Background image of page 10
UU/IT 3/23/10 | #11 @ UU/IT Safety rules Drawn Swing-components should only be changed by Listener methods Never call directly on a Listener method Components can be changed before they are drawn but not after ”pack()” and ”setVisible(true)”
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course 1MD 003 taught by Professor Larsoestreicher during the Spring '10 term at Uppsala.

Page1 / 37

EventsAndThreads - Graphic Interface Programming II Events...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online