diff options
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/appearance')
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java | 164 | ||||
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java | 161 |
2 files changed, 178 insertions, 147 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java index 578401e..598f5cb 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java @@ -44,23 +44,19 @@ package org.jdesktop.j3d.examples.appearance; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import java.awt.GraphicsConfiguration; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.geometry.ColorCube; +import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class AppearanceMixed extends Applet { - - private java.net.URL bgImage; - private java.net.URL texImage; +public class AppearanceMixed extends javax.swing.JFrame { - private SimpleUniverse u = null; + private java.net.URL texImage = null; + private java.net.URL bgImage = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; static class MyCanvas3D extends Canvas3D { private GraphicsContext3D gc; @@ -433,76 +429,96 @@ public class AppearanceMixed extends Applet { } - public AppearanceMixed() { - } - - public AppearanceMixed(java.net.URL bgurl, java.net.URL texurl) { - bgImage = bgurl; - texImage = texurl; - } - public void init() { - if (bgImage == null) { - // the path to the image for an applet - try { - bgImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - 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(); + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + // Create a MyCanvas3D using the preferred configuration MyCanvas3D c = new MyCanvas3D(config); - add("Center", c); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - 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); - public void destroy() { - u.cleanup(); + return c; } + /** + * Creates new form AppearanceMixed + */ + public AppearanceMixed() { - // - // The following allows AppearanceMixed to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // the path to the image file for an application - java.net.URL bgurl = null; - java.net.URL texurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - texurl = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new AppearanceMixed(bgurl, texurl), 700, 700); + if (bgImage == null) { + // the path to the image for an applet + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } + + if (texImage == null) { + // 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(); + univ.addBranchGraph(scene); + } + + // ---------------------------------------------------------------- + + /** 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("AppearanceMixed"); + 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 AppearanceMixed().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java index 8d57c48..1ef7471 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java @@ -44,21 +44,19 @@ package org.jdesktop.j3d.examples.appearance; -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 com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class AppearanceTest extends Applet { +public class AppearanceTest extends javax.swing.JFrame { private java.net.URL texImage = null; private java.net.URL bgImage = null; - - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; private BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -110,7 +108,6 @@ public class AppearanceTest extends Applet { return objRoot; } - private Appearance createAppearance(int idx) { Appearance app = new Appearance(); @@ -305,78 +302,96 @@ public class AppearanceTest extends Applet { return objTrans; } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public AppearanceTest() { - } - - public AppearanceTest(java.net.URL bgurl, java.net.URL texurl) { - bgImage = bgurl; - texImage = texurl; - } - - public void init() { - if (bgImage == null) { - // the path to the image for an applet - try { - bgImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - 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(); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); - } + /** + * Creates new form AppearanceTest + */ + public AppearanceTest() { + if (bgImage == null) { + // the path to the image for an applet + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } + + if (texImage == null) { + // 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(); + univ.addBranchGraph(scene); + } - // - // The following allows AppearanceTest to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // the path to the image file for an application - java.net.URL bgurl = null; - java.net.URL texurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - texurl = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new AppearanceTest(bgurl, texurl), 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("AppearanceTest"); + 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 AppearanceTest().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } |