diff options
author | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-14 18:11:17 +0000 |
---|---|---|
committer | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-14 18:11:17 +0000 |
commit | 39d071c598f993a69999ec06cdff6e38cb5448c0 (patch) | |
tree | 42fb19a1c6fdd3be845505466fadf1567882676c /src/classes/org | |
parent | 7f2ec5f282081ddc2510dc03d5d625f3e6078833 (diff) |
Modified program to access texture files via the Resources class.
Diffstat (limited to 'src/classes/org')
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java | 144 | ||||
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java | 49 |
2 files changed, 93 insertions, 100 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java b/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java index 026cfe9..f1ebf02 100644 --- a/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java +++ b/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java @@ -55,6 +55,7 @@ import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.image.BufferedImage; +import org.jdesktop.j3d.examples.Resources; public class MultiTextureTest extends Applet implements ItemListener{ @@ -203,66 +204,60 @@ public class MultiTextureTest extends Applet implements ItemListener{ } public void init() { - if (stoneImage == null) { - // the path to the image for an applet - try { - stoneImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); + if (stoneImage == null) { + // the path to the image for an applet + stoneImage = Resources.getResource("resources/images/stone.jpg"); + if (stoneImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + + if (skyImage == null) { + // the path to the image for an applet + skyImage = Resources.getResource("resources/images/bg.jpg"); + if (skyImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - if (skyImage == null) { - // the path to the image for an applet - try { - skyImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.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); - - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); - - ViewingPlatform viewingPlatform = u.getViewingPlatform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - viewingPlatform.setNominalViewingTransform(); - - // add orbit behavior but disable translate - OrbitBehavior orbit = - new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | - OrbitBehavior.DISABLE_TRANSLATE); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); - orbit.setSchedulingBounds(bounds); - viewingPlatform.setViewPlatformBehavior(orbit); - - u.addBranchGraph(scene); - - // create the gui - choice = new Choice(); - choice.addItem("stone + light"); - choice.addItem("stone"); - choice.addItem("lightMap"); - choice.addItem("sky"); - choice.addItem("stone + sky"); - choice.addItemListener(this); - add("North", choice); - + + setLayout(new BorderLayout()); + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + add("Center", c); + + BranchGroup scene = createSceneGraph(); + u = new SimpleUniverse(c); + + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + + // add orbit behavior but disable translate + OrbitBehavior orbit = + new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | + OrbitBehavior.DISABLE_TRANSLATE); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); + orbit.setSchedulingBounds(bounds); + viewingPlatform.setViewPlatformBehavior(orbit); + + u.addBranchGraph(scene); + + // create the gui + choice = new Choice(); + choice.addItem("stone + light"); + choice.addItem("stone"); + choice.addItem("lightMap"); + choice.addItem("sky"); + choice.addItem("stone + sky"); + choice.addItemListener(this); + add("North", choice); + } public void destroy() { @@ -302,19 +297,24 @@ public class MultiTextureTest extends Applet implements ItemListener{ } public static void main(String argv[]) - { - java.net.URL stoneURL = null; - java.net.URL skyURL = null; - // the path to the image for an application - try { - stoneURL = new java.net.URL("file:../images/stone.jpg"); - skyURL = new java.net.URL("file:../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new MultiTextureTest(stoneURL, skyURL), 750, 750); +{ + java.net.URL stoneURL = null; + java.net.URL skyURL = null; + // the path to the image for an application + + stoneURL = Resources.getResource("resources/images/stone.jpg"); + if (stoneURL == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + + skyURL = Resources.getResource("resources/images/bg.jpg"); + if (skyURL == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + + new MainFrame(new MultiTextureTest(stoneURL, skyURL), 750, 750); } } diff --git a/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java b/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java index b6ab08f..5ac421e 100644 --- a/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java +++ b/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java @@ -46,13 +46,13 @@ package org.jdesktop.j3d.examples.texture; 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.geometry.Box; import javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class TextureImage extends Applet { @@ -118,14 +118,11 @@ public class TextureImage extends Applet { public void init() { if (texImage == null) { // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } + texImage = Resources.getResource("resources/images/stone.jpg"); + if (texImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } } setLayout(new BorderLayout()); GraphicsConfiguration config = @@ -156,25 +153,21 @@ public class TextureImage extends Applet { public static void main(String[] args) { java.net.URL url = null; if (args.length > 0) { - try { - url = new java.net.URL("file:" + args[0]); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - else { - // the path to the image for an application - try { - url = new java.net.URL("file:../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - new MainFrame(new TextureImage(url), 256, 256); + try { + url = new java.net.URL("file:" + args[0]); + } catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } else { + // the path to the image for an application + url = Resources.getResource("resources/images/stone.jpg"); + if (url == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + } + new MainFrame(new TextureImage(url), 256, 256); } } |