Search in sources :

Example 1 with JmeCanvasContext

use of com.jme3.system.JmeCanvasContext in project jmonkeyengine by jMonkeyEngine.

the class TestCanvas method createCanvas.

public static void createCanvas(String appClass) {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas();
    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
}
Also used : AppSettings(com.jme3.system.AppSettings) LegacyApplication(com.jme3.app.LegacyApplication)

Example 2 with JmeCanvasContext

use of com.jme3.system.JmeCanvasContext in project jmonkeyengine by jMonkeyEngine.

the class TestSafeCanvas method main.

public static void main(String[] args) throws InterruptedException {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    final TestSafeCanvas app = new TestSafeCanvas();
    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas(true);
    JmeCanvasContext context = (JmeCanvasContext) app.getContext();
    Canvas canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
    Thread.sleep(3000);
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            app.stop();
        }
    });
    frame.getContentPane().add(canvas);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    Thread.sleep(3000);
    frame.getContentPane().remove(canvas);
    Thread.sleep(3000);
    frame.getContentPane().add(canvas);
}
Also used : JmeCanvasContext(com.jme3.system.JmeCanvasContext) AppSettings(com.jme3.system.AppSettings) JFrame(javax.swing.JFrame) Canvas(java.awt.Canvas) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 3 with JmeCanvasContext

use of com.jme3.system.JmeCanvasContext in project jmonkeyengine by jMonkeyEngine.

the class TestApplet method createCanvas.

public static void createCanvas(String appClass) {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    //        settings.setRenderer(AppSettings.JOGL);
    JmeSystem.setLowPermissions(true);
    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
    app.setSettings(settings);
    app.createCanvas();
    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
}
Also used : AppSettings(com.jme3.system.AppSettings) LegacyApplication(com.jme3.app.LegacyApplication)

Example 4 with JmeCanvasContext

use of com.jme3.system.JmeCanvasContext in project jmonkeyengine by jMonkeyEngine.

the class AppletHarness method createCanvas.

private void createCanvas() {
    AppSettings settings = new AppSettings(true);
    // load app cfg
    if (appCfg != null) {
        InputStream in = null;
        try {
            in = appCfg.openStream();
            settings.load(in);
            in.close();
        } catch (IOException ex) {
            // Called before application has been created ....
            // Display error message through AWT
            JOptionPane.showMessageDialog(this, "An error has occured while " + "loading applet configuration" + ex.getMessage(), "jME3 Applet", JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (IOException ex) {
                }
        }
    }
    if (assetCfg != null) {
        settings.putString("AssetConfigURL", assetCfg.toString());
    }
    settings.setWidth(getWidth());
    settings.setHeight(getHeight());
    JmeSystem.setLowPermissions(true);
    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
    appToApplet.put(app, this);
    app.setSettings(settings);
    app.createCanvas();
    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(getWidth(), getHeight());
    add(canvas);
    app.startCanvas();
}
Also used : AppSettings(com.jme3.system.AppSettings) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 5 with JmeCanvasContext

use of com.jme3.system.JmeCanvasContext in project jmonkeyengine by jMonkeyEngine.

the class AppHarness method createCanvas.

private void createCanvas() {
    AppSettings settings = new AppSettings(true);
    // load app cfg
    if (appCfg != null) {
        try {
            InputStream in = appCfg.openStream();
            settings.load(in);
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    settings.setWidth(getWidth());
    settings.setHeight(getHeight());
    settings.setAudioRenderer(null);
    JmeSystem.setLowPermissions(true);
    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
    app.setSettings(settings);
    app.createCanvas();
    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(getWidth(), getHeight());
    add(canvas);
    app.startCanvas();
}
Also used : AppSettings(com.jme3.system.AppSettings) InputStream(java.io.InputStream) IOException(java.io.IOException) LegacyApplication(com.jme3.app.LegacyApplication)

Aggregations

AppSettings (com.jme3.system.AppSettings)5 LegacyApplication (com.jme3.app.LegacyApplication)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 JmeCanvasContext (com.jme3.system.JmeCanvasContext)1 Canvas (java.awt.Canvas)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 JFrame (javax.swing.JFrame)1