MouseTest2 - 03/04/09 01:08:37 MouseTest2.java /...

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

View Full Document Right Arrow Icon
03/04/09 01:08:37 1 MouseTest2.java // MouseTest2.java // // by Dave Small // v1.0 200611.01: created // v1.1 200711.26: GUI creation moved to EDT // v2.0 200903.03: significantly expanded for CIS 4930: Concurrent Programming // //============================================================================= // MousePanel // - clicking on panel selects square region; double clicking deselects //----------------------------------------------------------------------------- // illustrates: // - MouseListeners (click events) // - MouseMotionListeners (movement events) // - changing the cursor // - adding/removing listeners // //============================================================================= // MousePanelFrame // - displays a MousePanel //----------------------------------------------------------------------------- // illustrates: // - setting content pane contents // - BorderLayout manager // - menu building // - ActionListeners // - buttons // - how to run a long task initiated in response to an event on a worker // thread and when it has completed, use SwingUtilities.invokeLater() // to update the GUI // //============================================================================= // MouseTest2 // - driver class for the demo //----------------------------------------------------------------------------- // illustrates: // - canonical way to construct GUI: pass task to SwingUtilities.invokeLater() // //============================================================================= import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import java.awt.Color; import java.awt.Graphics2D; import java.util.Random; //###################################################################### class MouseTest2 { static private final int WIDTH = 400; static private final int HEIGHT = 400; public static void main( String[] args ) { SwingUtilities.invokeLater( new Runnable() { public void run() { createAndShowGUI(); } } );
Background image of page 1

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

View Full DocumentRight Arrow Icon
03/04/09 01:08:37 2 MouseTest2.java } private static void createAndShowGUI() { // create the mouse panel MousePanel panel = new MousePanel( WIDTH, HEIGHT ); panel.initialize(); // create the frame to hold it MousePanelFrame frame = new MousePanelFrame( panel ); frame.attachMenuBar(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); // layout and display the GUI frame.pack(); // no need to validate(); frame.setVisible( true ); } } //###################################################################### class
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

MouseTest2 - 03/04/09 01:08:37 MouseTest2.java /...

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

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