Applet to Demonstrate Control of Multithreading

This applet enforces the the single thread rule for Swing programming.

This is achieved by inserting invokeLater() in the event dispatching thread to ensure that the updating of the progress text - via a JLabel - takes place within the main worker thread. This has the effect of delaying the action until it can be executed within the main worker threat, avoiding conflict with the dispatching thread.

The 1st click on the visible button activates the 1st thread in AcionListener, which brings up the JPanels displaying the JSpinner - set up to produce dates. A 2nd click on showDate, then activates a 2nd thread, which produces the date from JSpinner.

class butRead implements java.awt.event.ActionListener {
   public void actionPerformed(ActionEvent e) {
      String buttonString = e.getActionCommand();
      ..........
      ..........      
      EventQueue.invokeLater (new Runnable () {
           public void run () {
              displayThread2();
           } 
         });
      ..........
      ..........        
      }
   }

This Java applet has been created using jdk1.5.0_02. It has the class structure shown in the UML diagram.

[UML Diagram]

Implemented by
John R. Oliver
Tel: +44 1494-488-409
e-Mail: john.r.oliver@btinternet.com

Web page and Java Class files updated
wef 24 November 2006.


[Return to Home Page] [Button JDA]