diff options
Diffstat (limited to 'src')
6 files changed, 85 insertions, 137 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java index e191259..b9d6185 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java @@ -189,7 +189,7 @@ public class VertexAttrTestCg extends javax.swing.JFrame { String vertexProgram = null; try { - vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/myshader_vp.cg")); + vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/vertexshader_vp.cg")); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java index 744086c..573e27e 100644 --- a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java +++ b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java @@ -53,6 +53,7 @@ import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.applet.MainFrame; +import org.jdesktop.j3d.examples.Resources; /** * Class FourByFour @@ -147,8 +148,8 @@ public class FourByFour extends Applet implements ActionListener { host = getCodeBase().getHost(); try { - inStream = new BufferedInputStream - (new URL(getCodeBase(), "instructions.txt").openStream(), 8192); + URL instrURL = Resources.getResource("four_by_four/instructions.txt"); + inStream = new BufferedInputStream((instrURL).openStream(), 8192); text = new byte[5000]; int character = inStream.read(); int count = 0; @@ -166,8 +167,8 @@ public class FourByFour extends Applet implements ActionListener { else { try { - inStream = new BufferedInputStream - (new FileInputStream("instructions.txt")); + URL instrURL = Resources.getResource("four_by_four/instructions.txt"); + inStream = new BufferedInputStream((instrURL).openStream(), 8192); text = new byte[5000]; int character = inStream.read(); int count = 0; @@ -189,8 +190,8 @@ public class FourByFour extends Applet implements ActionListener { names = new String[20]; if (appletFlag) { try { - inStream = new BufferedInputStream - (new URL(getCodeBase(), "scores.txt").openStream(), 8192); + URL scoreURL = Resources.getResource("four_by_four/scores.txt"); + inStream = new BufferedInputStream((scoreURL).openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32,44); @@ -222,8 +223,8 @@ public class FourByFour extends Applet implements ActionListener { } else { try { - inStream = new BufferedInputStream - (new FileInputStream("scores.txt")); + URL scoreURL = Resources.getResource("four_by_four/scores.txt"); + inStream = new BufferedInputStream((scoreURL).openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32,44); diff --git a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java index aa649f7..d3f581a 100644 --- a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java +++ b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java @@ -44,25 +44,17 @@ package org.jdesktop.j3d.examples.geometry_by_ref; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; -import javax.swing.event.*; -import javax.swing.border.*; -import com.sun.j3d.utils.behaviors.mouse.*; import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.geometry.Box; -import com.sun.j3d.utils.geometry.ColorCube; import java.awt.image.*; -import java.awt.color.ColorSpace; -import com.sun.j3d.utils.geometry.*; +import org.jdesktop.j3d.examples.Resources; public class ImageComponentByReferenceTest extends JApplet implements ActionListener { @@ -251,33 +243,28 @@ public class ImageComponentByReferenceTest extends JApplet implements ActionList } public void init() { + + texImage = Resources.getResource("resources/images/one.jpg"); if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - + System.err.println("resources/images/one.jpg not found"); + System.exit(1); + } + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); - BranchGroup scene = createSceneGraph();u = new SimpleUniverse(c); + BranchGroup scene = createSceneGraph();u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); - Container contentPane = getContentPane(); - JPanel p = new JPanel(); - BoxLayout boxlayout = new BoxLayout(p, - BoxLayout.Y_AXIS); - p.setLayout(boxlayout); + Container contentPane = getContentPane(); + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.setLayout(boxlayout); contentPane.add("Center", c); - - contentPane.add("South", p); - - p.add(createImagePanel()); - + + contentPane.add("South", p); + + p.add(createImagePanel()); + } public void destroy() { @@ -287,21 +274,16 @@ public class ImageComponentByReferenceTest extends JApplet implements ActionList public static void main(String[] args) { java.net.URL url = null; // the path to the image file for an application - try { - url = new java.net.URL("file:../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - + url = Resources.getResource("resources/images/one.jpg"); + if (url == null) { + System.err.println("resources/images/one.jpg not found"); + System.exit(1); + } + new MainFrame(new ImageComponentByReferenceTest(url), 800, 700); } void createRaster( BranchGroup scene) { - - - // Create raster geometries and shapes Vector3f trans = new Vector3f( ); Transform3D tr = new Transform3D( ); @@ -319,9 +301,6 @@ public class ImageComponentByReferenceTest extends JApplet implements ActionList raster.setImage( image[2] ); Shape3D sh = new Shape3D( raster, new Appearance( ) ); scene.addChild( sh ); - - - } } diff --git a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java index 78edf99..464ae1a 100644 --- a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java +++ b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java @@ -44,20 +44,18 @@ package org.jdesktop.j3d.examples.geometry_by_ref; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; import com.sun.j3d.utils.behaviors.vp.*; import java.nio.*; +import org.jdesktop.j3d.examples.Resources; public class InterleavedNIOBuffer extends JApplet implements ActionListener { @@ -336,31 +334,18 @@ public class InterleavedNIOBuffer extends JApplet implements ActionListener { public void init() { // create textures - + texImage1 = Resources.getResource("resources/images/bg.jpg"); if (texImage1 == null) { - // the path to the image for an applet - try { - texImage1 = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/bg.jpg not found"); System.exit(1); - } } + texImage2 = Resources.getResource("resources/images/one.jpg"); if (texImage2 == null) { - // the path to the image for an applet - try { - texImage2 = new java.net.URL(getCodeBase().toString() + - "../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/one.jpg not found"); System.exit(1); - } } - + Container contentPane = getContentPane(); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); @@ -431,13 +416,16 @@ public class InterleavedNIOBuffer extends JApplet implements ActionListener { java.net.URL texURL1 = null; java.net.URL texURL2 = null; // the path to the image for an application - try { - texURL1 = new java.net.URL("file:../images/bg.jpg"); - texURL2 = new java.net.URL("file:../images/one.jpg"); + texURL1 = Resources.getResource("resources/images/bg.jpg"); + if (texURL1 == 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); + + texURL2 = Resources.getResource("resources/images/one.jpg"); + if (texURL2 == null) { + System.err.println("resources/images/one.jpg not found"); + System.exit(1); } Frame frame = new MainFrame(new InterleavedNIOBuffer(texURL1, texURL2), diff --git a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java index 788e1f6..bc570d0 100644 --- a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java +++ b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java @@ -44,19 +44,17 @@ package org.jdesktop.j3d.examples.geometry_by_ref; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; import com.sun.j3d.utils.behaviors.vp.*; +import org.jdesktop.j3d.examples.Resources; public class InterleavedTest extends JApplet implements ActionListener { @@ -315,29 +313,16 @@ public class InterleavedTest extends JApplet implements ActionListener { public void init() { // create textures - + texImage1 = Resources.getResource("resources/images/bg.jpg"); if (texImage1 == null) { - // the path to the image for an applet - try { - texImage1 = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/bg.jpg not found"); System.exit(1); - } } + texImage2 = Resources.getResource("resources/images/one.jpg"); if (texImage2 == null) { - // the path to the image for an applet - try { - texImage2 = new java.net.URL(getCodeBase().toString() + - "../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/one.jpg not found"); System.exit(1); - } } Container contentPane = getContentPane(); @@ -410,13 +395,16 @@ public class InterleavedTest extends JApplet implements ActionListener { java.net.URL texURL1 = null; java.net.URL texURL2 = null; // the path to the image for an application - try { - texURL1 = new java.net.URL("file:../images/bg.jpg"); - texURL2 = new java.net.URL("file:../images/one.jpg"); + texURL1 = Resources.getResource("resources/images/bg.jpg"); + if (texURL1 == 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); + + texURL2 = Resources.getResource("resources/images/one.jpg"); + if (texURL2 == null) { + System.err.println("resources/images/one.jpg not found"); + System.exit(1); } Frame frame = new MainFrame(new InterleavedTest(texURL1, texURL2), diff --git a/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java b/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java index 60333bb..919cc6e 100644 --- a/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java +++ b/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java @@ -46,7 +46,6 @@ package org.jdesktop.j3d.examples.oriented_shape3d; import java.applet.Applet; import java.awt.BorderLayout; -import java.awt.event.*; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; @@ -56,9 +55,9 @@ import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.io.*; import java.awt.*; import com.sun.j3d.utils.behaviors.vp.*; +import org.jdesktop.j3d.examples.Resources; public class OrientedPtTest extends Applet { @@ -225,26 +224,17 @@ public class OrientedPtTest extends Applet { public void init() { // the paths to the image files for an applet + earthImage = Resources.getResource("resources/images/earth.jpg"); if (earthImage == null) { - try { - earthImage = new java.net.URL(getCodeBase().toString() + - "../images/earth.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - if (stoneImage == null) { - try { - stoneImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } + System.err.println("resources/images/earth.jpg not found"); + System.exit(1); + } + + stoneImage = Resources.getResource("resources/images/stone.jpg"); + if (stoneImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); @@ -282,15 +272,17 @@ public class OrientedPtTest extends Applet { public static void main(String[] args) { java.net.URL earthURL = null; java.net.URL stoneURL = null; - try { - // the paths to the image files for an application - earthURL = new java.net.URL("file:../images/earth.jpg"); - stoneURL = new java.net.URL("file:../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } + earthURL = Resources.getResource("resources/images/earth.jpg"); + if (earthURL == null) { + System.err.println("resources/images/earth.jpg not found"); + System.exit(1); + } + + stoneURL = Resources.getResource("resources/images/stone.jpg"); + if (stoneURL == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } new MainFrame(new OrientedPtTest(earthURL, stoneURL), 400, 400); } |