import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; import java.awt.event.WindowAdapter ; import java.awt.event.WindowEvent ; import javax.swing.JButton ; import javax.swing.JFrame ; import javax.swing.SwingUtilities ; import com.jogamp.opengl.util.Animator ; public class JoglHangTest1 implements ActionListener { private class TestWindowAdapter extends WindowAdapter { public void windowClosed( WindowEvent e ) { _animator.stop() ; System.exit( 0 ) ; } public void windowClosing( WindowEvent e ) { _animator.stop() ; System.exit( 0 ) ; } } ////////////////////////////////////////////////////////////////////////// private Animator _animator ; public static void main( String args[] ) { try { new JoglHangTest1() ; } catch( Exception e ) { System.err.println( "Exception in JoglHangTest1.main(): " + e ) ; e.printStackTrace() ; } } ////////////////////////////////////////////////////////////////////////// public JoglHangTest1() { JFrame frame = new JFrame() ; JButton b = new JButton( "Make Frame" ) ; b.addActionListener( this ) ; frame.getContentPane().add( b ) ; frame.pack() ; frame.setVisible( true ) ; } ////////////////////////////////////////////////////////////////////////// public void actionPerformed( ActionEvent event ) { // If _makeFrame is called synchronously here then it always works. // If _makeFrame is called through invokeLater then we get the // "don't display until you wiggle the mouse" behavior and sometimes // get deadlocks. SwingUtilities.invokeLater( new Runnable() { public void run() { _makeFrame( "JOGL Hang Test 1", 0, 90, 300, 300 ) ; } } ) ; } ////////////////////////////////////////////////////////////////////////// private void _makeFrame( String title, int x, int y, int width, int height ) { JFrame frame = new JFrame( title ) ; frame.setBounds( x, y, width, height ) ; BigRedXCanvas canvas = new BigRedXCanvas() ; frame.getContentPane().add( canvas ) ; frame.addWindowListener( new TestWindowAdapter() ) ; frame.setVisible( true ) ; _animator = new Animator( canvas ) ; _animator.start() ; } //////////////////////////////////////////////////////////////////////////// }