diff options
author | kcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-03-07 17:42:45 +0000 |
---|---|---|
committer | kcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-03-07 17:42:45 +0000 |
commit | d2f4b6c478a34d0089711a7bb8286bd0d04abbfb (patch) | |
tree | 535d86f45afccd54017d7f9a647302d1409d4312 /src/classes/org/jdesktop/j3d/examples/picking | |
parent | 19e30a5771eb1ec413e562c0d99b6263978dfba0 (diff) |
Merged changes between 1.4.0-beta4 and 1.4.0-fcs into dev-1_5 branch
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/picking')
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java | 136 |
1 files changed, 77 insertions, 59 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java b/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java index 29eaec0..6828d6a 100644 --- a/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java +++ b/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java @@ -44,22 +44,20 @@ package org.jdesktop.j3d.examples.picking; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; -import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; +import com.sun.j3d.utils.image.TextureLoader; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class TickTockPicking extends Applet { +public class TickTockPicking extends javax.swing.JFrame { + private SimpleUniverse univ = null; + private BranchGroup scene = null; // path the the texture map image private java.net.URL texImage = null; - private SimpleUniverse u = null; - public BranchGroup createSceneGraph(Canvas3D c) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -384,65 +382,85 @@ public class TickTockPicking extends Applet { return objTrans; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - public TickTockPicking() { - } - - public TickTockPicking(java.net.URL url) { - texImage = url; - } - - public void init() { - if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(c); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form HelloUniverse + */ + public TickTockPicking() { + + // the path to the image for an applet + texImage = Resources.getResource("resources/images/stone.jpg"); + if (texImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(c); + univ.addBranchGraph(scene); } + + // ---------------------------------------------------------------- - // - // The following allows TickTockPicking to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // the path the the texture map for an application - java.net.URL url = null; - try { - url = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new TickTockPicking(url), 700, 700); + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("TickTockPicking"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new TickTockPicking().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } |