Home | History | Annotate | Download | only in awt
      1 package jme3test.awt;
      2 
      3 import com.jme3.app.SimpleApplication;
      4 import com.jme3.material.Material;
      5 import com.jme3.math.Vector3f;
      6 import com.jme3.scene.Geometry;
      7 import com.jme3.scene.shape.Box;
      8 import com.jme3.system.AppSettings;
      9 import com.jme3.system.JmeCanvasContext;
     10 import java.awt.Canvas;
     11 import java.awt.event.WindowAdapter;
     12 import java.awt.event.WindowEvent;
     13 import javax.swing.JFrame;
     14 
     15 public class TestSafeCanvas extends SimpleApplication {
     16 
     17     public static void main(String[] args) throws InterruptedException{
     18         AppSettings settings = new AppSettings(true);
     19         settings.setWidth(640);
     20         settings.setHeight(480);
     21 
     22         final TestSafeCanvas app = new TestSafeCanvas();
     23         app.setPauseOnLostFocus(false);
     24         app.setSettings(settings);
     25         app.createCanvas();
     26         app.startCanvas(true);
     27 
     28         JmeCanvasContext context = (JmeCanvasContext) app.getContext();
     29         Canvas canvas = context.getCanvas();
     30         canvas.setSize(settings.getWidth(), settings.getHeight());
     31 
     32 
     33 
     34         Thread.sleep(3000);
     35 
     36         JFrame frame = new JFrame("Test");
     37         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
     38         frame.addWindowListener(new WindowAdapter() {
     39             @Override
     40             public void windowClosing(WindowEvent e) {
     41                 app.stop();
     42             }
     43         });
     44         frame.getContentPane().add(canvas);
     45         frame.pack();
     46         frame.setLocationRelativeTo(null);
     47         frame.setVisible(true);
     48 
     49         Thread.sleep(3000);
     50 
     51         frame.getContentPane().remove(canvas);
     52 
     53         Thread.sleep(3000);
     54 
     55         frame.getContentPane().add(canvas);
     56     }
     57 
     58     @Override
     59     public void simpleInitApp() {
     60         flyCam.setDragToRotate(true);
     61 
     62         Box b = new Box(Vector3f.ZERO, 1, 1, 1);
     63         Geometry geom = new Geometry("Box", b);
     64         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
     65         mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
     66         geom.setMaterial(mat);
     67         rootNode.attachChild(geom);
     68     }
     69 }
     70