import java.awt.event.WindowEvent;\r
\r
import javax.swing.JFrame;\r
+import javax.swing.SwingUtilities;\r
\r
import com.badlogic.gdx.Application;\r
import com.badlogic.gdx.ApplicationListener;\r
import com.badlogic.gdx.Input;\r
import com.badlogic.gdx.InputProcessor;\r
import com.badlogic.gdx.Version;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
/**\r
* An implemenation of the {@link Application} interface based on Jogl for Windows, Linux and Mac. Instantiate this class with\r
* \r
*/\r
public final class JoglApplication implements Application {\r
- static {\r
- JoglNativesLoader.loadLibraries();\r
+ static { \r
Version.loadLibrary();\r
}\r
\r
- final JoglGraphics graphics; \r
- final JoglInput input; \r
- final JoglFiles files; \r
- final JoglAudio audio; \r
+ JoglGraphics graphics; \r
+ JoglInput input; \r
+ JoglFiles files; \r
+ JoglAudio audio; \r
JFrame frame;\r
\r
\r
* @param width the width of the surface in pixels\r
* @param height the height of the surface in pixels\r
* @param useGL20IfAvailable wheter to use OpenGL 2.0 if it is available or not\r
- */\r
- public JoglApplication (ApplicationListener listener, String title, int width, int height, boolean useGL20IfAvailable) {\r
- graphics = new JoglGraphics(listener, title, width, height, useGL20IfAvailable);\r
- input = new JoglInput(graphics.getCanvas());\r
- audio = new JoglAudio();\r
- files = new JoglFiles();\r
-\r
- Gdx.app = this;\r
- Gdx.graphics = this.getGraphics();\r
- Gdx.input = this.getInput();\r
- Gdx.audio = this.getAudio();\r
- Gdx.files = this.getFiles();\r
- \r
- initialize(title, width, height);\r
+ */ \r
+ public JoglApplication (final ApplicationListener listener, final String title, final int width, final int height, final boolean useGL20IfAvailable) {\r
+ try {\r
+ SwingUtilities.invokeAndWait( new Runnable() {\r
+ public void run() { \r
+ JoglNativesLoader.loadLibraries();\r
+ graphics = new JoglGraphics(listener, title, width, height, useGL20IfAvailable);\r
+ input = new JoglInput(graphics.getCanvas());\r
+ audio = new JoglAudio();\r
+ files = new JoglFiles();\r
+ \r
+ Gdx.app = JoglApplication.this;\r
+ Gdx.graphics = JoglApplication.this.getGraphics();\r
+ Gdx.input = JoglApplication.this.getInput();\r
+ Gdx.audio = JoglApplication.this.getAudio();\r
+ Gdx.files = JoglApplication.this.getFiles();\r
+ \r
+ initialize(title, width, height);\r
+ }\r
+ });\r
+ } catch (Exception e) {\r
+ throw new GdxRuntimeException("Creating window failed");\r
+ } \r
}\r
\r
private void initialize(String title, int width, int height) {\r
- graphics.getCanvas().setPreferredSize(new Dimension(width, height));\r
- \r
- frame = new JFrame(title); \r
+ frame = new JFrame(title);\r
+ graphics.getCanvas().setPreferredSize(new Dimension(width, height)); \r
frame.setSize(width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top + frame.getInsets().bottom\r
+ height);\r
frame.add(graphics.getCanvas(), BorderLayout.CENTER); \r