Loading .obj model file to applet returns AccessControlException

I examined other applets where this code seems to work. Yet, I can't get it to function properly within my code.
     URL fileURL = null;
        try {
         fileURL = new URL( getDocumentBase(), "test.obj");
        } catch (Exception e) {
         System.err.println("Exception: "+ e);
         System.exit(1);
        ObjectFile f = new ObjectFile();
        Scene s = null;
        try {
            s = f.load( fileURL );
        catch (Exception e) {
            System.err.println(e);
            System.exit(1);
        }I can load image files without any problems. Any help will be appreciated.

Forgot to post the error message..
java.security.AccessControlException: access denied (java.io.FilePermission /home/squier/cwol/html/test.obj read)
java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM)
     at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
     at java.security.AccessController.checkPermission(AccessController.java:427)
     at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
     at java.lang.SecurityManager.checkExit(SecurityManager.java:744)
     at java.lang.Runtime.exit(Runtime.java:88)
     at java.lang.System.exit(System.java:868)
     at cwol.BattleApp.loadModel(BattleApp.java:157)
     at cwol.BattleApp.init(BattleApp.java:63)
     at sun.applet.AppletPanel.run(AppletPanel.java:374)
     at java.lang.Thread.run(Thread.java:595)

Similar Messages

  • Trouble loading .OBJ model

    Hello all,
    I can't seem to load a .OBJ model with this code. The code is not returning any exceptions, but the window gives me nothing but a black screen. The model is nothing more than a cube, and I am entering a valid file location.
    public class Model3d
        private String location;
        private SceneBase s;
        public Model3d(String fileLocation)
            location = fileLocation;
            s = (SceneBase)getScene();
        public SceneBase getSceneBase()
              TransformGroup tg = new TransformGroup();
              Transform3D transform = new Transform3D();
              Vector3f vector = new Vector3f(0, 0, 0);
              transform.setTranslation(vector);
              tg.setTransform(transform);
              s.addViewGroup(tg);
              return s;
        private Scene getScene()
            try
                ObjectFile of = new ObjectFile(ObjectFile.RESIZE);
                Scene s = of.load(new FileReader(location));
                return s;
            catch(java.io.FileNotFoundException e)
                System.out.println("lol");
                e.printStackTrace();
                return null;
    }When I call:
    su = new SimpleUniverse();
    BranchGroup group = new BranchGroup();
    group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    group.addChild(new Model3d("C:\\square.obj").getSceneBase().getSceneGroup());
    su.getViewingPlatform().setNominalViewingTransform();
    su.addBranchGraph(group);I get a black screen. Help? Thanks in advance.

    Hi,
    Sorry for the delay
    I found this at Java Tips and changed it to work on my computer. Just change dlamp.obj (appears once) to square.obj. I think it'll work if you place the file in the same folder as your java file as well as the C:// drive.
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.GraphicsConfiguration;
    import java.io.FileNotFoundException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.media.j3d.Alpha;
    import javax.media.j3d.AmbientLight;
    import javax.media.j3d.Background;
    import javax.media.j3d.BoundingSphere;
    import javax.media.j3d.BranchGroup;
    import javax.media.j3d.Canvas3D;
    import javax.media.j3d.DirectionalLight;
    import javax.media.j3d.RotationInterpolator;
    import javax.media.j3d.Transform3D;
    import javax.media.j3d.TransformGroup;
    import javax.vecmath.Color3f;
    import javax.vecmath.Point3d;
    import javax.vecmath.Vector3f;
    import com.sun.j3d.loaders.IncorrectFormatException;
    import com.sun.j3d.loaders.ParsingErrorException;
    import com.sun.j3d.loaders.Scene;
    import com.sun.j3d.loaders.objectfile.ObjectFile;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
    import com.sun.j3d.utils.universe.PlatformGeometry;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import com.sun.j3d.utils.universe.ViewingPlatform;
    public class ObjLoad extends Applet {
    private boolean spin = false;
    private boolean noTriangulate = false;
    private boolean noStripify = false;
    private double creaseAngle = 60.0;
    private URL filename = null;
    private SimpleUniverse u;
    private BoundingSphere bounds;
    public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.7);
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);
    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);
    int flags = ObjectFile.RESIZE;
    if (!noTriangulate)
    flags |= ObjectFile.TRIANGULATE;
    if (!noStripify)
    flags |= ObjectFile.STRIPIFY;
    ObjectFile f = new ObjectFile(flags,
    (float) (creaseAngle * Math.PI / 180.0));
    Scene s = null;
    try {
    s = f.load(filename);
    } catch (FileNotFoundException e) {
    System.err.println(e);
    System.exit(1);
    } catch (ParsingErrorException e) {
    System.err.println(e);
    System.exit(1);
    } catch (IncorrectFormatException e) {
    System.err.println(e);
    System.exit(1);
    objTrans.addChild(s.getSceneGroup());
    bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    if (spin) {
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
    4000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator = new RotationInterpolator(
    rotationAlpha, objTrans, yAxis, 0.0f,
    (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);
    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);
    return objRoot;
    private void usage() {
    System.out
    .println("Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>");
    System.out.println(" -s Spin (no user interaction)");
    System.out.println(" -n No triangulation");
    System.out.println(" -t No stripification");
    System.out
    .println(" -c Set crease angle for normal generation (default is 60 without");
    System.out
    .println(" smoothing group info, otherwise 180 within smoothing groups)");
    System.exit(0);
    } // End of usage
    public void init() {
    if (filename == null) {
    // Applet
    try {
                   filename = new URL("file","","dlamp.obj");
    } catch (MalformedURLException e) {
    System.err.println(e);
    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();
    u = new SimpleUniverse(c);
    // add mouse behaviors to the ViewingPlatform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();
    PlatformGeometry pg = new PlatformGeometry();
    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    pg.addChild(ambientLightNode);
    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color,
    light1Direction);
    light1.setInfluencingBounds(bounds);
    pg.addChild(light1);
    DirectionalLight light2 = new DirectionalLight(light2Color,
    light2Direction);
    light2.setInfluencingBounds(bounds);
    pg.addChild(light2);
    viewingPlatform.setPlatformGeometry(pg);
    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    viewingPlatform.setNominalViewingTransform();
    if (!spin) {
    OrbitBehavior orbit = new OrbitBehavior(c,
    OrbitBehavior.REVERSE_ALL);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,
    0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);
    u.addBranchGraph(scene);
    // Caled if running as a program
    public ObjLoad(String[] args) {
    if (args.length != 0) {
    for (int i = 0; i < args.length; i++) {
    if (args.startsWith("-")) {
    if (args[i].equals("-s")) {
    spin = true;
    } else if (args[i].equals("-n")) {
    noTriangulate = true;
    } else if (args[i].equals("-t")) {
    noStripify = true;
    } else if (args[i].equals("-c")) {
    if (i < args.length - 1) {
    creaseAngle = (new Double(args[++i])).doubleValue();
    } else
    usage();
    } else {
    usage();
    } else {
    try {
    if ((args[i].indexOf("file:") == 0)
    || (args[i].indexOf("http") == 0)) {
    filename = new URL(args[i]);
    } else if (args[i].charAt(0) != '/') {
    filename = new URL("file:./" + args[i]);
    } else {
    filename = new URL("file:" + args[i]);
    } catch (MalformedURLException e) {
    System.err.println(e);
    System.exit(1);
    // Running as an applet
    public ObjLoad() {
    public void destroy() {
    u.cleanup();
    // The following allows ObjLoad to be run as an application
    // as well as an applet
    public static void main(String[] args) {
    new MainFrame(new ObjLoad(args), 700, 700);

  • Issue in iPlanet loading obj.conf file in admin console module

    Dear all,
    I have done following chanegs in obj.conf file to block insecure http methods,but whenever I try to access admin module of iPlanet and restart, all manual changes done in obj.conf disappears.
    Only one time it asked me with message that file has been modified manually do you want to load?
    but this is not happening every time.I am using iplanet 9.
    Please let me know if there is any issue with this or I am missing something.
    to just brief, only after trying 20 times it asked me above mentioned message
    ---obj.conf file contents----
    <Object name="WebCon1" ppath="*/WebCon/*">
    *<Client method="(GET|POST)">*
    AuthTrans fn="match-browser" browser="MSIE*" ssl-unclean-shutdown="true"*
    *</Client>*
    *<Client method="(HEAD|PUT|TRACE|TRACK|SEARCH|INDEX|OPTIONS|DELETE|MKDIR|SHOWMETHOD|UNLINK|CHECKIN|TEXTSEARCH|SPACEJUMP|CONNECT|PATCH|PROPFIND|PROPPATCH|MKCOL|COPY|MOVE|LOCK|UNLOCK|CHECKOUT|RMDIR|ACL|VERSION-CONTROL|REPORT|UNCHECKOUT|ORDERPATCH)">*
    *AuthTrans fn="set-variable" remove-headers="transfer-encoding" set-headers="content-length: -1" error="405"*
    *</Client>*
    NameTrans fn="pfx2dir" from="/mc-icons" dir="/home/cedera/iPlanetServer/Installation/ns-icons" name="es-internal"
    PathCheck fn="unix-uri-clean"
    PathCheck fn="find-pathinfo"
    ObjectType fn="type-by-extension"
    ObjectType fn="force-type" type="text/plain"
    Service method="(GET|POST)" type="image/gif" fn="send-file"
    Service method="(GET|POST)" type="image/jpeg" fn="send-file"
    Service method="(GET|POST)" type="text/css" fn="send-file"
    Service method="(GET|POST)" type="application/x-javascript" fn="send-file"
    Service method="(GET|POST)" type="magnus-internal/imagemap" fn="imagemap"
    Service method="(GET|POST)" type="magnus-internal/directory" fn="send-error" path="/WebCon/WebCon/restrict.htm"
    Service method="(GET|POST)" fn="wl_proxy" WebLogicHost="10.10.61.224" WebLogicPort="444" HungServerRecoverSecs="600" Debug="ALL" DebugConfigInfo="TRUE" RequireSSLHostMatch="FALSE" WLLogFile="/home/cedera/iPlanetServer/Installation/https-webcon2/logs/Log_JSP.txt" PathTrim="/WebCon" PathPrepend="/WebConverter" SecureProxy="ON" URIContainsSpace="true" ErrorPage="/home/cedera/iPlanetServer/Installation/docs/WebCon/WebCon/serviceUnavailable.htm" MaxPostSize="-1" DefaultFileName="WebCon/login.jsp" ConnectTimeoutSecs="10" ConnectRetrySecs="2" WLDNSRefreshInterval="0" TrustedCAFile="/home/cedera/iPlanetServer/Installation/https-webcon2/config/trustedcafile.pem"
    AddLog fn="flex-log" name="access"
    </Object>
    I have added contents marked in bold manually....
    but it was not picking up it from frontend...then suddenly after 20 time, it picked up these changes in admin...
    but now if I am trying to change in <client> tag , but it does not recognise any new changes done manually...it loads same obj.conf...whenever i restart instance from frontend...
    Edited by: sweetvish on Nov 9, 2009 9:26 PM

    After making manual changes in obj.conf, have you tried clicking the 'Apply' link in admin console and then choosing 'Load configuration Changes' option?

  • Loading PNG image file from Applet?

    Hi All,
    My applet running on IE6 and it will often loads 100 PNG image files from a webserver.
    Size of PNG file is about 60Kb so 100*60=6000 Kb ~ 6M.
    In theory, the applet will took 6M of memory to store all 100 files. In practical, it tooks about
    6M* 25 = 150M of memory, that make my applet run in out of memory sometimes.
    I know the reason, may be the brower/applet convert the PNG file format to BMP file format before showing on the screen.
    So the main point here is the applet should not loads all 100 files into the memory,
    it should loads only 10 files at the same time, another 90 files should be cached in memory as PNG file format, not BMP image file format to save the memory usage.
    Is this solution possible in applet field?
    If it is possible how can I implement it?
    And please show me better solution if anys.
    Many Thanks.

    I know the reason, may be the brower/applet convert the PNG file format to
    BMP file format before showing on the screen.This sounds VERY unlikely! Why should the browser do that? And the applet does what you have coded I hope!
    Your problem is probably somewhere else. And it has nothing to do with applets I presume. Use a heap analyzer tool to find out what hogs the memory. A thorough code review can't hurt either. If you still thinks it is the images though, then just don't load them all at once then.

  • SQL Loader - CSV Data file with carraige returns and line fields

    Hi,
    I have a CSV data file with occasional carraige returns and line feeds in between, which throws my SQL loader script off. Sql loader, takes the characters following the carraige return as a new record and gives me error. Is there a way I could handle carraige returns and linefeeds in SQL Loader.
    Please help. Thank you for your time.
    This is my Sql Loader script.
    load data
    infile 'D:\Documents and Settings\user1\My Documents\infile.csv' "str '\r\n'"
    append
    into table MYSCHEMA.TABLE1
    fields terminated by ','
    OPTIONALLY ENCLOSED BY '"'
    trailing nullcols
    ( NAME CHAR(4000),
    field2 FILLER,
    field3 FILLER,
    TEST DEPT CHAR(4000)
    )

    You can "regexp_replace" the columns for special characters

  • Loading OBJ-File BY COPY ?

    Hello!
    I want to load a 3D-Model in OBJ-Format in my Scene with the standard Objectloader com.sun.j3d.loaders.objectfile. This works basically well.
    But I need to get hold of the Vertices of the Model and their colors. And this is the Problem:
    -I try to get the Coordinates from the Shape3Ds GeometryArray with getCoordinate() and receive the following error:
    GeometryArray: cannot directly access data in BY_REFERENCE mode
    This is as I assume because the loader creates the Shape3D BY REFERENCE.
    Is there another loader or a trick, so that the GeometryArrays of my loaded OBJ-Models are set up as BY COPY?
    Code where I load my Model:
    public BranchGroup UseOBJModel_Old(String path)
            ObjectFile loader = new ObjectFile();
            BranchGroup bg = new BranchGroup();
            Shape3D shape = new Shape3D();
            try
                Scene tmpScene = loader.load(path);
                 Enumeration children = tmpScene.getSceneGroup().getAllChildren();
                //Combining all Shape3Ds from the OBJ-Model into one single shape
                while(children.hasMoreElements())
                     Shape3D tmp = (Shape3D)children.nextElement();
                     shape.addGeometry(tmp.getGeometry());      
                //TODO: Hard setting of Color for OBJ-Shape.Can be improved later
                Appearance objApp = new Appearance();
                Material objMat = new Material();
                ColoringAttributes col = new ColoringAttributes();
                objMat.setAmbientColor(new Color3f(.3f,.3f,.3f));
                objMat.setDiffuseColor(new Color3f(.5f,.5f,.5f));
                objMat.setSpecularColor(new Color3f(.6f,.6f,.6f));
                objMat.setLightingEnable(true);
                objApp.setMaterial(objMat);
                objApp.setColoringAttributes(col);
                col.setColor(.6f,.6f,.6f);
                shape.setAppearance(objApp);
                bg.addChild(shape);
                return bg;
            }Code where the Error occurs:
    for(int j = 0; j < originalArray.getValidVertexCount() / divisor; j++)//Calculate Points for LOD-Models
                for(int k = 0; k < divisor; k++ )
                   // This tells me that the Array is NOT in BY REFERENCE-Mode. Funny thing
                    System.out.println("By-Reference-Status: " + originalArray.getCapability(GeometryArray.BY_REFERENCE));
                   originalArray.getColor(index,col[k]);//Here's the Error
                   originalArray.getCoordinate(index++,pos[k]);//And here,too
            }Hope I could make it clear what my Problem is, as this is my first post here...
    Bye
    Chris

    D'Oh!
    First post, and already posted the wrong code...
    This is the right code, where I load the OBJ-Model:
    public void UseOBJModel(String path)
            ObjectFile loader = new ObjectFile();
            Shape3D shape = new Shape3D();
            try
                Scene tmpScene = loader.load(path);
                 Enumeration children = tmpScene.getSceneGroup().getAllChildren();
                 Shape3D tmp = (Shape3D)children.nextElement();
                 shape.setGeometry(tmp.getGeometry(),0);//This for killing the leading null in the GeometryList
                //Combining all Shape3Ds from the OBJ-Model into one single shape
                while(children.hasMoreElements())
                    tmp = (Shape3D)children.nextElement();
                     shape.addGeometry(tmp.getGeometry());      
                //TODO: Hard setting of Color for OBJ-Shape.Can be improved later
                Appearance objApp = new Appearance();
                Material objMat = new Material();
                ColoringAttributes col = new ColoringAttributes();
                objMat.setAmbientColor(new Color3f(.3f,.3f,.3f));
                objMat.setDiffuseColor(new Color3f(.5f,.5f,.5f));
                objMat.setSpecularColor(new Color3f(.6f,.6f,.6f));
                objMat.setLightingEnable(true);
                objApp.setMaterial(objMat);
                objApp.setColoringAttributes(col);
                col.setColor(.6f,.6f,.6f);
                shape.setAppearance(objApp);
                SetOriginalShape(shape);
            catch(FileNotFoundException e)
                System.err.println("Something went wrong while loading OBJ-File");
        }Sorry...

  • Loading .obj and .mtl in Java, how I can do this?

    Well, I'm having problem with this, I'm doing my Course Conclusion Work related with augmented reality in java (JARToolKit) and I want to import models 3D in the format .obj, but I need to import it's materials too that is in the file .mtl. Anyone that already use this or do this if can help me I will be grateful, I need this and I trying everything, any help will be very good to me.
    Thanks,
    Jairo.

    Hi,
    the Java 3D API includes a utility for loading '.obj/.mtl'-files: com.sun.j3d.loaders.objectfile.ObjectFile.
    August

  • Is it possible to make a morph between loaded 3d-models?

    I want to load obj-models and then make a morph between them. It's seems like it is not possible in Java3D. Or am I wrong?
    A morph is made from GeometryArrays which come from shape3d-object. It is possible to get a scene from the loaded model with the load() method in the ObjectFile class. But is it also possible to exctract a geometryarray from the model, so a morph can be made?
    Check out the morphs that I already have:
    http://www.astralvisuals.com/ShapeShiftersnew.htm

    It's not easy but it's possible:
    At first you have to decide which vertex_1 from model 1 has to fade into which vertex_2 from model 2 (To decide this just check the distance).
    If the two models don't have the same vertex amout just let the model with more vertexes fade into that with the lower amout of vertexes and than invert the animation if needed.
    After this is done you just have to move the vertexes from frame to frame from the old position to the new position.
    This is how to morph models but I don't know how to morph textures :-/

  • Loading in .obj & .mtl files

    HI all, I'm quite new to Java3D and 3D graphics and I'm struggling to understand how to load in models correctly. I have the latest Java3D binaries, Java 6, and I'm using Flux Studio 2.1 (as I'm also interested in X3D).
    Ok the problem. I can import an .obj file into Java3D and have it displayed on the canvas. The object seems to require a texture to be visible; if my knowledge serves me correctly without a texture it may not have a material which enables lighting (could be wrong). Anyway. Loading in a single cube with a brick texture is fine. The moment I make a simply roof with a different texture and attached to the cube (the walls), the geometry loads in Java3D but it uses the first texture (the brick) to cover both the walls (cube) and roof! I don't understand why this second texture has vanished.
    I've never looked at an .obj file before but after having opened up the .mtl file it looks like a line is missing:
    # File produced by
    newmtl dad_Roof
    Ns 4
    d 1
    illum 2
    Kd 1.000000 0.000000 0.000000
    Ka 0.200000 0.200000 0.200000
    Ks 0.000000 0.000000 0.000000
    newmtl dad_Walls
    Ns 4
    d 1
    illum 2
    Kd 1.000000 0.000000 0.000000
    Ka 0.200000 0.200000 0.200000
    Ks 0.000000 0.000000 0.000000
    map_Kd stonetile10.gif
    There is no map_Kd (not sure what it is - must be a texture) entry for the dad_Roof which is being referenced in the .obj file.
    I have tried putting in my own map_Kd entry, but it does nothing. Help! :-)
    Incase it's something to do with my Java3D code, here's a very simple example of what I am using:
    ObjectFile objFileLoader = new ObjectFile(ObjectFile.RESIZE);       
            File modelFile = new File("D:\\Profiles\\aan025\\My Documents\\test.obj");
            URL url = null;
            try {
                url = modelFile.toURI().toURL();
            } catch(MalformedURLException exp) {
                exp.printStackTrace();
            try {
                Scene scene = objFileLoader.load(url);  
                branchGroup = scene.getSceneGroup(); 
                analyseBG(branchGroup);
            } catch(FileNotFoundException exp) {
                exp.printStackTrace();
            return branchGroup;Thanks very much. I'm really enjoying Java3D and 3D modeling.

    Has anyone had any luck in loading multiple textures from an .obj file?
    Take one obj file, along with a .mtl file. Load it via ObjectFile into the latest Java3D. The scene should be two shapes with a different textures each i.e., two different .jpg files. Can this be done? Or is it one texture per Shape3D loaded in from the .obj and .mtl file?

  • Loading an image into an Applet from a JAR file

    Hello everyone, hopefully a simple question for someone to help me with!
    Im trying to load some images into an applet, currently it uses the JApplet.getImage(url) method just before registering with a media tracker, which works but for the sake of efficiency I would prefer the images all to be contained in the jar file as oppossed to being loaded individually from the server.
    Say I have a class in a package eg, 'com.mydomain.myapplet.class.bin' and an images contained in the file structure 'com.mydomain.myapplet.images.img.gif' how do I load it (and waiting for it to be loaded before preceeding?
    I've seen lots of info of the web for this but much of it is very old (pre 2000) and im sure things have changed a little since then.
    Thanks for any help!

    I don't touch applets, so I can't help you there, but here's some Friday Fun: tracking image loading.
    import java.awt.*;
    import java.awt.image.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.imageio.event.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class ImageLoader extends SwingWorker<BufferedImage, Void> {
        private URL url;
        private JLabel target;
        private IIOReadProgressAdapter listener = new IIOReadProgressAdapter() {
            @Override public void imageProgress(ImageReader source, float percentageDone) {
                setProgress((int)percentageDone);
            @Override public void imageComplete(ImageReader source) {
                setProgress(100);
        public ImageLoader(URL url, JLabel target) {
            this.url = url;
            this.target = target;
        @Override protected BufferedImage doInBackground() throws IOException {
            ImageInputStream input = ImageIO.createImageInputStream(url.openStream());
            try {
                ImageReader reader = ImageIO.getImageReaders(input).next();
                reader.addIIOReadProgressListener(listener);
                reader.setInput(input);
                return reader.read(0);
            } finally {
                input.close();
        @Override protected void done() {
            try {
                target.setIcon(new ImageIcon(get()));
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
        //demo
        public static void main(String[] args) throws IOException {
            final URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot.jpg");
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch(url);
        static void launch(URL url) {
            JLabel imageLabel = new JLabel();
            final JProgressBar progress = new JProgressBar();
            progress.setBorderPainted(true);
            progress.setStringPainted(true);
            JScrollPane scroller = new JScrollPane(imageLabel);
            scroller.setPreferredSize(new Dimension(800,600));
            JPanel content = new JPanel(new BorderLayout());
            content.add(scroller, BorderLayout.CENTER);
            content.add(progress, BorderLayout.SOUTH);
            JFrame f = new JFrame("ImageLoader");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(content);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            ImageLoader loader = new ImageLoader(url, imageLabel);
            loader.addPropertyChangeListener( new PropertyChangeListener() {
                 public  void propertyChange(PropertyChangeEvent evt) {
                     if ("progress".equals(evt.getPropertyName())) {
                         progress.setValue((Integer)evt.getNewValue());
                         System.out.println(evt.getNewValue());
                     } else if ("state".equals(evt.getPropertyName())) {
                         if (SwingWorker.StateValue.DONE == evt.getNewValue()) {
                             progress.setIndeterminate(true);
            loader.execute();
    abstract class IIOReadProgressAdapter implements IIOReadProgressListener {
        @Override public void imageComplete(ImageReader source) {}
        @Override public void imageProgress(ImageReader source, float percentageDone) {}
        @Override public void imageStarted(ImageReader source, int imageIndex) {}
        @Override public void readAborted(ImageReader source) {}
        @Override public void sequenceComplete(ImageReader source) {}
        @Override public void sequenceStarted(ImageReader source, int minIndex) {}
        @Override public void thumbnailComplete(ImageReader source) {}
        @Override public void thumbnailProgress(ImageReader source, float percentageDone) {}
        @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {}
    }

  • Loading a text file in a gzip or zip archive using an applet to a String

    How do I load a text file in a gzip or zip archive using an applet to a String, not a byte array? Give me both gzip and zip examples.

    This doesn't work:
              try
                   java.net.URL url = new java.net.URL(getCodeBase() + filename);
                   inputStream = new java.io.BufferedInputStream(url.openStream());
                   if (filename.toLowerCase().endsWith(".txt.gz"))
                        inputStream = (java.io.InputStream)(new java.util.zip.GZIPInputStream(inputStream));
                   else if (filename.toLowerCase().endsWith(".zip"))
                        java.util.zip.ZipInputStream zipInputStream = new java.util.zip.ZipInputStream(inputStream);
                        java.util.zip.ZipEntry zipEntry = zipInputStream.getNextEntry();
                        while (zipEntry != null && (zipEntry.isDirectory() || !zipEntry.getName().toLowerCase().endsWith(".txt")))
                             zipEntry = zipInputStream.getNextEntry();
                        if (zipEntry == null)
                             zipInputStream.close();
                             inputStream.close();
                             return "";
                        inputStream = zipInputStream;
                   else
                   byte bytes[] = new byte[10000000];
                   byte s;
                   int i = 0;
                   while (((s = inputStream.read())) != null)
                        bytes[i++] = s;
                   inputStream.close();
            catch (Exception e)
              }

  • Loading Obj file with its .mtl

    Hai guys,
    I am new to java3D. I need to load the .obj which has the .mtl and the respective pics for its texture.(The .obj file .mtl and the relevant pics are all in the same folder) The Problem is obj file is being loaded but the output we got is no where near what we see in 3DMax. What is the problem?. Where i am going wrong.
    Thanks in Advance,
    Prakash Anandaraj. C

    D'Oh!
    First post, and already posted the wrong code...
    This is the right code, where I load the OBJ-Model:
    public void UseOBJModel(String path)
            ObjectFile loader = new ObjectFile();
            Shape3D shape = new Shape3D();
            try
                Scene tmpScene = loader.load(path);
                 Enumeration children = tmpScene.getSceneGroup().getAllChildren();
                 Shape3D tmp = (Shape3D)children.nextElement();
                 shape.setGeometry(tmp.getGeometry(),0);//This for killing the leading null in the GeometryList
                //Combining all Shape3Ds from the OBJ-Model into one single shape
                while(children.hasMoreElements())
                    tmp = (Shape3D)children.nextElement();
                     shape.addGeometry(tmp.getGeometry());      
                //TODO: Hard setting of Color for OBJ-Shape.Can be improved later
                Appearance objApp = new Appearance();
                Material objMat = new Material();
                ColoringAttributes col = new ColoringAttributes();
                objMat.setAmbientColor(new Color3f(.3f,.3f,.3f));
                objMat.setDiffuseColor(new Color3f(.5f,.5f,.5f));
                objMat.setSpecularColor(new Color3f(.6f,.6f,.6f));
                objMat.setLightingEnable(true);
                objApp.setMaterial(objMat);
                objApp.setColoringAttributes(col);
                col.setColor(.6f,.6f,.6f);
                shape.setAppearance(objApp);
                SetOriginalShape(shape);
            catch(FileNotFoundException e)
                System.err.println("Something went wrong while loading OBJ-File");
        }Sorry...

  • Loading a txt file into an applet.

    as the topic suggests: I want to load a text file into an applet.
    i only got this far:
    public static String load(String path)
                            String date = "";
            File file = new File(path);
            try {
             // Load
            catch (IOException e) {
             e.printStackTrace();
            return date;
           } how do i load the file?
    is it possible to return the data in a list (more convenient)?
    Message was edited by:
    Comp-Freak

    as the topic suggests: I want to load a text file
    into an applet.
    i only got this far:
    public static String load(String path)
    String date = "";
    (path);
            try {
             // Load
            catch (IOException e) {
             e.printStackTrace();
            return date;
           } how do i load the file?
    is it possible to return the data in a list (more
    convenient)?
    Message was edited by:
    Comp-FreakFirst of all, you are going to have to sign your applet if you want access to the local file system (applets run on the client, not the server).
    Second of all ... looking at your code, what is "date?" Is it a String (guessing based on your return value...) here is a simple routine to read a text file, line by line:
    try {
       BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("myfile")));
       String input;
       while( (input = br.readLine() != null ) {
           System.out.println(input);
    }  catch (FileNotFoundException fnfe) { System.err.println("File not found."); }
       catch (IOException ioe) { ioe.printStackTrace(); }

  • How to load files into applets?

    Hi,
    I have developed a quiz applet. The quiz applet will have a button by clicking which one can start quiz. The quiz will open in a Jframe.
    At first the frame shows screen to enter a username (no checking for present).
    After you click login it takes the test quiz file as input and number of questions to appear in quiz.
    After that quiz program will be reading the quiz file specified (available in the same directory), then parsing the file getting questions and answers into Objects of questionRecord.
    From these questionRecords a question will be given in the frame at random.
    Finally, score will be displayed to the user.
    The program works well when it is compiled in eclipse. When I try the same program to run in browser (I'm using Mozilla), I can't load the quiz file. I dont find any errors as it running in the browser. I dont understand where the problem might be.
    Here is the Url: http://csee.wvu.edu/~srikantv/Assign/Assignment4Applet1164649158249.html
    If you want to look at.
    Please help..
    Thanx

    You can configure the browser or the plugin so that the java console is displayed.
    Your problem is probably that an applet which isn't signed isn't allowed to read files from the local filesystem.
    Kaj

  • Can i load a class in subdirectoy  inside a jar file using applet tag?

    hi every one.. thank you for reading ... i am really in dire need for the solution..
    my problem is that i have a jar file contianing a package which inturn contains my applet class...
    i am trying to access this applet class using a applet tag in html file. this html file is in same directory as the jar file. i am having no problems in windows but when i am doing this in linux apache server i was getting class not found exception. (already checked the file permissions). and when i am successful when using simple package directory instead of jar file . so gist of my quesition is "can i load a class in subdirectoy inside a jar file using applet tag in a html file"?

    When you tested in Windows were you using Internet Explorer? On Linux you will be using a different browser, usually Mozilla of some version, or Firefox. Note that the HTML tags for applets will be different between the browsers if you are using the object tag. Principally the classid value for the object tag will differ between Firefox and Internet Explorer.

Maybe you are looking for