• Main Page
  • Related Pages
  • Classes
  • Files
  • File List

RunStandalone.java

Go to the documentation of this file.
00001 
00002 import java.awt.Dimension;
00003 import java.awt.Toolkit;
00004 
00005 import javax.swing.JFrame;
00006 import javax.swing.SwingUtilities;
00007 
00008 
00009 /**
00010  *  Runs instance of the <code>JPWorld</code> component inside
00011  *  the stand-alone application with own <code>JFrame</code>.
00012  *  
00013  *  @author Mikica B Kocic
00014  */
00015 public class RunStandalone extends JFrame
00016 {
00017     /**
00018      *  Implements java.io.Serializable interface
00019      */
00020     private static final long serialVersionUID = -6852878245259708233L;
00021 
00022     /**
00023      *  Main component is instance of the <code>JPWorld</code>.
00024      */
00025     private JPWorld wopComponent = new JPWorld ();
00026 
00027     /**
00028      *  Adds main component <code>JPWorld</code> to the content pane.
00029      */
00030     public RunStandalone ()
00031     {
00032         super(
00033             "IP1-1.1: Multithreaded World of Particles (inefficient but educational)"
00034             );
00035         
00036         setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
00037 
00038         /* Adjust window dimensions not to exceed screen dimensions ...
00039          */
00040         Dimension win = new Dimension( 1024, 600 );
00041         Dimension scsz = Toolkit.getDefaultToolkit().getScreenSize();
00042         win.width  = Math.min( win.width, scsz.width );
00043         win.height = Math.min( win.height, scsz.height - 40 );
00044         setSize( win );
00045         setMinimumSize( new Dimension( 330, 100 ) );
00046         
00047         /* ... then center window on the screen.
00048          */
00049         setLocation( ( scsz.width - win.width )/2, ( scsz.height - 40 - win.height )/2 );
00050         
00051         /*  Register the thread tester component, then make frame visible
00052          */
00053         add( wopComponent );
00054         addKeyListener( wopComponent );
00055         setVisible( true );
00056         
00057         /* Start T1 & T2 tests delayed for 1 sec
00058          */
00059         wopComponent.startTests( 1f /*sec delay*/ );
00060     }
00061     
00062     /**
00063      *  Main program entry that creates and shows GUI.
00064      *  
00065      *  @param args   main program arguments
00066      */
00067     public static void main( String[] args ) 
00068     {
00069         /*  Create and show GUI
00070          */
00071         Runnable doCreateAndShowGUI = new Runnable () {
00072             public void run () {
00073                 new RunStandalone ();
00074             }
00075         };
00076 
00077         SwingUtilities.invokeLater( doCreateAndShowGUI );
00078     }
00079 }

Generated on Thu Dec 16 2010 12:28:54 for Multi-threaded World of Particles by  doxygen 1.7.2