diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/demos/es1/RedSquare.java | 40 | ||||
-rwxr-xr-x | src/demos/es2/RedSquare.java | 40 |
2 files changed, 58 insertions, 22 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 24da987..a7ede75 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -1,6 +1,7 @@ package demos.es1; import java.nio.*; +import java.util.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.nativewindow.*; @@ -74,10 +75,6 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public void mouseWheelMoved(MouseEvent e) { } - private void runInMain() { - run(); - } - public void run() { System.err.println(glp+" RedSquare.run() 0"); int width = 800; @@ -214,20 +211,41 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public static int USE_AWT = 1 << 0; public static void main(String[] args) { - String glprofile = null; int type = USE_NEWT ; + List threads = new ArrayList(); for(int i=0; i<args.length; i++) { if(args[i].equals("-awt")) { - type = USE_AWT; + type |= USE_AWT; } if(args[i].startsWith("-GL")) { - if(null!=glprofile) { - new RedSquare(glprofile, type).start(); - type = USE_NEWT ; + threads.add(new RedSquare(args[i].substring(1), type)); + } + } + if(threads.size()==0) { + threads.add(new RedSquare(null, type)); + } + Thread firstT = (Thread) threads.remove(0); + + for(Iterator i = threads.iterator(); i.hasNext(); ) { + ((Thread)i.next()).start(); + } + + // always run the first on main .. + firstT.run(); + + boolean done = false; + + while(!done) { + int aliveCount = 0; + for(Iterator i = threads.iterator(); i.hasNext(); ) { + if ( ((Thread)i.next()).isAlive() ) { + try { + Thread.sleep(100); + } catch (InterruptedException ie) {} + aliveCount++; } - glprofile=args[i].substring(1); } + done = 0==aliveCount ; } - new RedSquare(glprofile, type).runInMain(); } } diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java index bcbae3d..5f120a5 100755 --- a/src/demos/es2/RedSquare.java +++ b/src/demos/es2/RedSquare.java @@ -1,6 +1,7 @@ package demos.es2; import java.nio.*; +import java.util.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.nativewindow.*; @@ -66,10 +67,6 @@ public class RedSquare extends Thread implements WindowListener, MouseListener, public void mouseWheelMoved(MouseEvent e) { } - private void runInMain() { - run(); - } - public void run() { System.err.println(glp+" RedSquare.run()"); int width = 800; @@ -259,20 +256,41 @@ public class RedSquare extends Thread implements WindowListener, MouseListener, public static int USE_AWT = 1 << 0; public static void main(String[] args) { - String glprofile = null; int type = USE_NEWT ; + List threads = new ArrayList(); for(int i=0; i<args.length; i++) { if(args[i].equals("-awt")) { - type = USE_AWT; + type |= USE_AWT; } if(args[i].startsWith("-GL")) { - if(null!=glprofile) { - new RedSquare(glprofile, type).start(); - type = USE_NEWT ; + threads.add(new RedSquare(args[i].substring(1), type)); + } + } + if(threads.size()==0) { + threads.add(new RedSquare(null, type)); + } + Thread firstT = (Thread) threads.remove(0); + + for(Iterator i = threads.iterator(); i.hasNext(); ) { + ((Thread)i.next()).start(); + } + + // always run the first on main .. + firstT.run(); + + boolean done = false; + + while(!done) { + int aliveCount = 0; + for(Iterator i = threads.iterator(); i.hasNext(); ) { + if ( ((Thread)i.next()).isAlive() ) { + try { + Thread.sleep(100); + } catch (InterruptedException ie) {} + aliveCount++; } - glprofile=args[i].substring(1); } + done = 0==aliveCount ; } - new RedSquare(glprofile, type).runInMain(); } } |