From db51908057c333598179879522a230fc4929aeb3 Mon Sep 17 00:00:00 2001 From: jada Date: Tue, 14 Feb 2006 19:26:20 +0000 Subject: Modified programs to access data files via Resources class --- .../j3d/examples/appearance/AppearanceMixed.java | 61 ++++++++++------------ .../j3d/examples/appearance/AppearanceTest.java | 61 +++++++++++----------- 2 files changed, 59 insertions(+), 63 deletions(-) (limited to 'src/classes/org/jdesktop/j3d/examples/appearance') diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java index 578401e..bed5d0b 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java @@ -46,14 +46,13 @@ 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 javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class AppearanceMixed extends Applet { @@ -443,28 +442,23 @@ public class AppearanceMixed extends Applet { 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); - } - } - + 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 - 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()); + // the path to the image for an applet + texImage = Resources.getResource("resources/images/apimage.jpg"); + if (texImage == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + } + + setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); @@ -495,14 +489,17 @@ public class AppearanceMixed extends Applet { // 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); + bgurl = Resources.getResource("resources/images/bg.jpg"); + if (bgurl == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + texurl = Resources.getResource("resources/images/apimage.jpg"); + if (texurl == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + + new MainFrame(new AppearanceMixed(bgurl, texurl), 700, 700); } } diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java index 8d57c48..03f25d8 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java @@ -46,12 +46,12 @@ 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 javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class AppearanceTest extends Applet { @@ -316,28 +316,23 @@ public class AppearanceTest extends Applet { 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); - } - } - + // 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 - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } + // the path to the image for an applet + texImage = Resources.getResource("resources/images/apimage.jpg"); + if (texImage == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + } + setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); @@ -369,14 +364,18 @@ public class AppearanceTest extends Applet { // 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); + + bgurl = Resources.getResource("resources/images/bg.jpg"); + if (bgurl == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + texurl = Resources.getResource("resources/images/apimage.jpg"); + if (texurl == null) { + System.err.println("resources/images/apimage.jpg not found"); + System.exit(1); + } + + new MainFrame(new AppearanceTest(bgurl, texurl), 700, 700); } } -- cgit v1.2.3