Threads2 - CS 580 Client-Server Programming Spring...

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

View Full Document Right Arrow Icon
CS 580 Client-Server Programming Spring Semester, 2010 25 Feb, 2010 Copyright ©, All rights reserved. 2010 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http:// www.opencontent.org/opl.shtml ) license defines the copyright on this document.
Background image of page 1

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

View Full DocumentRight Arrow Icon
References 2 Creating a GUI With JFC/Swing, http://java.sun.com/docs/books/tutorial/uiswing/ Concurrency in Swing,http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html Cancellable Activities, Doug Lea, October 1998, http://gee.cs.oswego.edu/dl/cpj/cancel.html Concurrent Programming in Java: Design Principles and Patterns, Doug Lea, Addison-Wesley, 1997 Java on-line documentation http://java.sun.com/javase/6/docs/api/ Java Network Programming 2nd Ed., Harold, O'Reilly, Chapter 5 Java Performance and Scalability Vol. 1, Dov Bulka, 2000
Background image of page 2
3 Threads & GUIs
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 GUI programs are event driven Actions on GUI components generate events Events are placed in a event queue & processed
Background image of page 4
The Rule 5 "All Swing components and related classes, unless otherwise documented, must be accessed on the event dispatching thread." From Java Swing documentation
Background image of page 5

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

View Full DocumentRight Arrow Icon
How 6 javax.swing.SwingUtilities.invokeLater(Runnable run) javax.swing.SwingUtilities.invokeAndWait (Runnable run)
Background image of page 6
Swing Hello World 7 import javax.swing.*; public class HelloWorldSwing { private static void createAndShowGUI() { JFrame frame = new JFrame("HelloWorldSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities. invokeLater (new Runnable() { public void run() { createAndShowGUI(); } }); } } Source from Creating a GUI With JFC/Swing, http://java.sun.com/docs/books/tutorial/uiswing/examples/start/ HelloWorldSwingProject/src/start//HelloWorldSwing.java
Background image of page 7

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

View Full DocumentRight Arrow Icon
Swing Thread Example 8 SDChat client reading a message from server Example 1 - Blocking GUI actions Example 2- One shot background thread Example 3 - Repeating background thread
Background image of page 8
GUI Thread Example - Blocking GUI actions 9 public class SwingGUI extends javax.swing.JFrame{ private javax.swing.JLabel fieldLabel; private javax.swing.JButton runButton; private javax.swing.JTextField resultField; private SDChatClient client = new SDChatClient(); public SwingGUI() { initComponents(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SwingGUI().setVisible(true); } }); }
Background image of page 9

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

View Full DocumentRight Arrow Icon
Creating the Window Components 10 private void initComponents() { resultField = new javax.swing.JTextField(); fieldLabel = new javax.swing.JLabel(); runButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Thread Example"); fieldLabel.setText("Result"); runButton.setText("Go"); runButton.addActionListener(new java.awt.event.ActionListener() {
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 59

Threads2 - CS 580 Client-Server Programming Spring...

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

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