Applet loading of images -- network or JAR approach faster?

hi all,
i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and incurred a network hit per image file.
to avoid the overhead of a separate network connection for each image file, i bundled all the images into the same JAR file that contains the applet. yet, the loading time for the applet is somehow slower now. i'm totally mystified.
i put the code for loading each image into a separate thread as well. here's the thread code:
BEGIN CODE
public class ImageLoaderThread extends Thread {
     private Hashtable images;
     private DesignApplet applet;
     public ImageLoaderThread(DesignApplet applet, Hashtable images, String imageFile) {
          super(imageFile);
          this.images = images;
          this.applet = applet;
     public void run() {
          try {
               System.out.println("Starting to load image ...");
               String imageFile = getName();
               InputStream is = applet.getClass().getResourceAsStream(imageFile);
               int arraySize = is.available() * 2; // CH: create extra space just in case
               System.out.println("Image Loader Thread: " + imageFile + "bytes available: " + arraySize);
               BufferedInputStream bis = new BufferedInputStream(is);
               byte[] byBuf = new byte[arraySize]; // a buffer large enough for our image
               int byteRead = bis.read(byBuf, 0, arraySize);
               Image buttonImage = Toolkit.getDefaultToolkit().createImage(byBuf);
               images.put(imageFile, buttonImage);
          catch(Exception e) {
               System.out.println("Exception while loading: " + getName());
               e.printStackTrace();
END CODE
imageFile is the name of an image file stored in the JAR file. it's not stored on the server anywhere, so i know the image is getting created from the JAR file. despite this, the speed of image creation seems tied to the network. in other words, when i attempt to load the applet over a slow link, it takes longer to load than over a fast link.
any ideas what i'm doing wrong? i'm seriously stumped and could use help. my goals are to minimize loading time of the applet while minimizing network hits for the server.
thanks!
p.s. if you want to play w/ the applet, click on the following link and click the "Customize" button: http://www.cengraving.com/s/z/Photo-plaques/PP024.jsp

Why are you using a thread to load each image why not just load the images in the gui thread?
Each thread you create takes a finite time to be started and stopped. This will surely have added to the load and startup time.
There is also blocking going on since using the Java Console I can see that each thread reports in sequence:
"Starting to load image ..."
And then after all threads have reported they are starting they then report in squence:
Image Loader Thread: " + imageFile + "bytes available: " + arraySize information.
This shows that there is at least some blocking going on with the threads.
I don't think using separate threads to do the loading is helping at all. Just load them one after another in the same thread (the thread all your threads are being started from).
The putting of the images into the images Hashtable will also be blocking since Hashtable is synchronized.

Similar Messages

  • Loading an image from a jar with web start

    Hi,
    I have a jar file that contains all the classes and .gif images that my program uses. I am trying to set this up to use web start. I have the .jnlp file working correctly, but I get i/o errors when my images are loaded via an ImageIcon.
    The Developer Guide says that "[t]he jar file will typically contain Java classes that contain the code for the particular application, but can also contain other resources, such as icons and configuration files, that are available through the getResource mechanism. "
    I can't figure out how getResource() works. I've tried this:
    ClassLoader.getSystemClassLoader().getResource(fileName).getContent()
    but the content it returns is an Object, Given the filename, it should be my gif, but I don't know what type of Object it is, much less how to turn it into an Image.
    Can't anyone help? I'd really appreciate it!
    Thanks,
    B. Danny K.

    use Thread.currentThread().getContextClassLoader().loadResource() to get the JNLPClassLoader.
    The system class loader will not find resources in jars loaded by java web start.
    /Dietz

  • Why can't I load the image files in the Jar file?

    I make an application in a structure bellowing:
    A.class
    images\a.gif
    images\b.gif
    and I packed all of them(include the images directory) into a A.jar file.
    when I run the A.jar file,the application can't load the images in the Jar file.
    How can I do to solve this problem?

    It isn't working. The URL that is returned is blank. I tried rearanginf my stuff a little. Now it is set up like the other guys. So all the classes aren't in a package. so its:
    MyClass.class
    Sounds/mysound.wav
    all of this is in a .jar file. If it isnt in a .jar file it works. Bit I have mor than one class so I would really like it in a .jar file. But when it is MyClass.class.getResource("sounds/mysound.wav") returns nothing. Not null. Just blank.

  • 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 an image present  in a JAR through an applet

    We are mgirating from MS JVM to SUN JVM.We are facing problems with loading bitmaps present in a Jar file.
    Here is the code snippet..
    iActive= Util.mgrlistApplet.getImage(Util.mgrlistApplet.getDocumentBase(), activeImage);
    Util is an user defined class.
    activeImage is the image file name.
    The above code works in MS JVM
    Thanks in advance.

    Try something like this:
    java.net.URL url = getClass().getResource("/images/progbar.gif");
    ImageIcon icon = new ImageIcon(url);
    JLabel label = new JLabel(icon);
    This will get the image progbar.gif will be relative to the root of the jar file and from the images directory. If you want to get it relative to the class that you are working in remove the / at the beginning.
    Chris

  • Issues with Loading Images from a Jar File

    This code snippet basically loops through a jar of gifs and loads them into a hashmap to be used later. The images all load into the HashMap just fine, I tested and made sure their widths and heights were changing as well as the buffer size from gif to gif. The problem comes in when some of the images are loaded to be painted they are incomplete it looks as though part of the image came through but not all of it, while other images look just fine. The old way in which we loaded the graphics didn't involve getting them from a jar file. My question is, is this a common problem with loading images from a jar from an applet? For a while I had tried to approach the problem by getting the URL of the image in a jar and passing that into the toolkit and creating the image that way, I was unsuccessful in getting that to work.
    //app is the Japplet
    MediaTracker tracker = new MediaTracker(app);
    //jf represents the jar file obj, enum for looping through jar entries
    Enumeration e = jf.entries();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    //buffer for reading image stream
    byte buffer [];
    while(e.hasMoreElements())
    fileName = e.nextElement().toString();
    InputStream inputstream = jf.getInputStream(jf.getEntry(fileName));
    buffer = new byte[inputstream.available()];
    inputstream.read(buffer);
    currentIm = toolkit.createImage(buffer);
    tracker.addImage(currentIm, 0);
    tracker.waitForAll();
    images.put(fileName.substring(0, fileName.indexOf(".")), currentIm);
    } //while
    }//try
    catch(Exception e)
    e.printStackTrace();
    }

    compressed files are not the problem. It is just the problem of the read not returning all the bytes. Here is a working implementation:
    InputStream is = jar.getInputStream(entry);
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    try{
    byte[] buf = new byte[1024];
    int read;
    while((read = is.read(buf)) > 0) {
    os.write(buf, 0, read);
    catch(Exception e){
         e.printStackTrace();
         return null;
    image = Toolkit.getDefaultToolkit().createImage(os.toByteArray());
    This works but I think you end up opening the jar a second time and downloading it from the server again. Another way of getting the images is using the class loader:
    InputStream is = MyApplet.class.getResourceAsStream(strImageName);
    In this case, the image file needs to be at the same level than MyApplet.class but you don't get the benefit of enumerating of the images available in the jar.

  • Loading all images from Jar include the directory structure.

    Hi I would like to puts all my images in a Jar. is it going to improve the loading speed?
    I have a ImageLibary that load all the images to a hashtable and access each image by their path and filename.
    I only have to input the image root directory and it will load all the images including sub-directory. If I decide to put these directories in a JAR. is this still going to work? Do all the class files has to be in the same JAR?
    use getResourse()?
    My current ImageLibary is like this:
    public class ImagesLibary extends Component
    private Hashtable imagesBank;
    private Vector imagesName;
    private MediaTracker tracker;
    public ImagesLibary()
    imagesBank = new Hashtable();
    imagesName = new Vector();
    tracker= new MediaTracker(this);
    loadImageFile("./images");
    for(int i=0; i<imagesName.size(); i++)
    String key = (String)imagesName.get(i);
    Image image = getToolkit().getImage(key);
    tracker.addImage(image, 0);
    try
    tracker.waitForID(0);
    catch (InterruptedException e)
    System.err.println("Loading image: " + key + " fails. " + e);
    imagesBank.put(key,image);
    System.out.println("Loaded: " + key);
    System.out.println("Total of " + imagesBank.size() + " images.");
    private void loadImageFile(String dir)
    File imageDir = new File(dir);
    File temp[] = imageDir.listFiles();
    for(int i=0; i<temp.length;i++)
    if (temp.isDirectory())
    loadImageFile(temp[i].getPath());
    else
    imagesName.add(temp[i].getPath());

    is it going to improve the loading speed?depends :)
    is this still going to work?some ajustments are needed... but thats done quickly.
    Do all the class files has to be in the same JAR?no. but it's easier to handle.
    use getResourse()?yes. don't know if u have to. but i do it this way :)
    inside an application:
    URL keyboardImagePath;
    keyboardImagePath = (new Object()).getClass().getResource("/gfx/keyboard.gif");
    Image kb=getToolkit().getImage(keyboardImagePath);inside an applet:
    URL path = (new Object()).getClass().getResource( "/icons/right.gif" );
    // now make the icon getting the gif from the url
    ImageIcon = new ImageIcon( path );inside a hybrid:
    URL keyboardImagePath;
    keyboardImagePath = (new Object()).getClass().getResource("/gfx/keyboard.gif");
    System.out.println("<-(application)load:"+keyboardImagePath); //if u wanna c what happens
    if(keyboardImagePath==null)
         keyboardImagePath=selfRef.getClass().getResource("/gfx/keyboard.gif");
         System.out.println("<-(applet)load:"+keyboardImagePath); //if u wanna c what happens
    Image kb=getToolkit().getImage(keyboardImagePath);hope that was helpfull :)

  • Applet loads full jar instead one resource

    Hi,
    i noticed that applet load full jar file instead loading one image!
    i load images with:
    InputStream in = this.getClass().getResourceAsStream(kaynakAdresi);how can i fix this?

    This will happen if the Jar is not being properly cached. Check your settings for the Plug-In and the browser; also check the headers are being sent correctly from the web server - if the expiry time etc are missing then the browser will not cache the file. Look up an HTTP sniffer if you need to trace the headers.,

  • Loading images from a jar file

    Hi,
    My application displays images, until it's placed in a JAR file, then it can't display them even though the JAR file contains the images.
    I saw this problem in a previous question which was solved using
    URL url = MyClass.class.getResource("abc.gif");
    Image img=Toolkit.getDefaultToolkit().getImage(url);
    ....which btw didn't work for me either......
    This method should be made obsolete using ImageIcon, which I am using, but the images still won't appear...
    Any suggestions?

    It works fine that way (...getClass().getResource....) until I create the jar file, and then I get a null pointer exception when it tries to load the image.
    When I use
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(("/images/imageName.jpg"));
    the application works but without the images.......

  • Loading an image in an applet

    I am trying to load and display an existing image to my applet and break the image up into segments to allow the pieces to be moved into their correct position. However it is only getting as far as cutting the image up but it does not complete loading the image. Below is the run() method im using to load it:
    public void run()
            int i;
            MediaTracker trackset;              // Tracker for images
            Image WholeImage;                 // The whole image
                        Image ResizedImage;
            ImageFilter filter;
         // Determine the size of the applet
         r = getSize();
            // Load up the image
            if (getParameter("SRC") == null)
              Error("Image filename not defined.");
         WholeImage = getImage(getDocumentBase(), getParameter("SRC"));
         // Scale original image if needed
            // Make the image load completely and put the image
            // into the track set.  Where it waits in paint() method.
            trackset = new MediaTracker(this);
            trackset.addImage(WholeImage, 1);
            // Mix up the puzzle
            System.out.println("Mixing puzzle.");
            PaintScreen = 2;
            repaint();
            try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            // Tell user of the wait for image loading
           //Trap trackset exceptions that track if the image
           //hasn't loaded properly and output to the user.
            PaintScreen = 0;
            repaint();
            try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            try {
               trackset.waitForID(1);
            } catch (InterruptedException e) {
               Error("Loading Interrupted!");
            // Check if image loaded up correctly
            //Where is image is held in the same directory
            //as the HTML file use getImage method to pass
            //getDocumentBase(), taking in the getParameter.
            if (WholeImage.getWidth(this) == -1)
                 PaintScreen = 3;
                 repaint();
                 WholeImage = getImage(getDocumentBase(), getParameter("SRC"));
                 trackset = new MediaTracker(this);
                 trackset.addImage(WholeImage, 1);
                 try {
                    trackset.waitForID(1);
                 } catch (InterruptedException e) {
                    Error("Loading Interrupted!");
                 if (WholeImage.getWidth(this) == -1)
                      PaintScreen = 4;
                      repaint();
                      stop();
                      return;
         // Resize picture if needed.
         int ResizeOption = integerFromString(getParameter("RESIZE"));
         if ((r.width != WholeImage.getWidth(this) ||
              r.height != WholeImage.getHeight(this)) &&
                ResizeOption != 0)
              if (ResizeOption == 2)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_FAST);
              else if (ResizeOption == 3)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_SMOOTH);
              else if (ResizeOption == 4)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_AREA_AVERAGING);
              else
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_DEFAULT);
              trackset.addImage(ResizedImage, 2);
              PaintScreen = 5;
              repaint();
              try {
              Thread.sleep(100);
              } catch (InterruptedException e) {
              try {
              trackset.waitForID(2);
              } catch (InterruptedException e) {
              Error("Loading Interrupted!");
              WholeImage = ResizedImage;
            // Complete loading image.  Start background loading other things
            // Also put image into the Graphics class
            // Split up main image into smaller images
            PaintScreen = 1;
            repaint();
            try {
               Thread.sleep(100);
            } catch (InterruptedException e){}
            piecewidth = WholeImage.getWidth(this) / piecesx;
            pieceheight = WholeImage.getHeight(this) / piecesy;
            System.out.println("Image has loaded.  X=" +
                               WholeImage.getWidth(this) + " Y=" +
                               WholeImage.getHeight(this));
            imageset = new Image[totalpieces];
            for (i = 0; i < totalpieces; i++)
                 filter = new CropImageFilter(GetPieceX(i) * piecewidth,
                                              GetPieceY(i) * pieceheight,
                                              piecewidth, pieceheight);
                 imageset[i] = createImage(new
                                           FilteredImageSource(WholeImage.getSource(),
                                                               filter));
            // Set up the mouse listener
            System.out.println("Adding mouse listener.");
            addMouseListener(this);
            // Complete mixing the image parts
            System.out.println("Displaying puzzle.");
            PaintScreen = -1;
            repaint();
            while (end != null)
              try {
                 Thread.sleep(100);
              } catch (InterruptedException e){}
         }Any help to where im going wrong would be much appreciated. Thanks!

    ive seen this one many times and it dosent work for me! Shouldnt the second parameter of the getImage(...) method not include the 'http://..." part as that what getDocumentBase() is for, returning the URL of the page the applet is embedded in? I have tried using code like this and event getting a printout of the doc/code base into the console to make sure my images are in the right place (.gif images), and nothing's happening, null pointer every time!
    {code}
    Image image;
    public void init() {
    // Load image
    image = getImage(getDocumentBase(), "http://hostname/image.gif");
    public void paint(Graphics g) {
    // Draw image
    g.drawImage(image, 0, 0, this);
    {code}
    ps this code is from the site mentioned above
    Edited by: Sir_Dori on Dec 8, 2008 8:37 AM

  • Loading Image outside the jar

    I have a .jar program that saves and loads imagens from a folder outside the jar. In my directory I have:
    myProg.jar
    images(folder)
    This is the way myProg.jar saves the images:
    BufferedImage myImage; //myImage is initialized somewhere else
    File file = new File("images/Pic"+temp+".jpg");
        try{
        ImageIO.write(myImage, "jpg", file);
           }catch(IOException io){}
    }catch(AWTException ea){}When I check the image is saved in my folder "images"
    Then, the prog tries to load the images this way:
    URL url = getClass().getResource("/images/"+name+".jpg");
    ImageIcon icon;
             if (url != null) {
                  icon = new ImageIcon(url);
                  picture.setIcon(icon);
             else {
                  url = getClass().getResource("/images/street.jpg");
                  icon = new ImageIcon(url);
                  picture.setIcon(icon);
             }Here I have an exception : Exception in thread "AWT-EventQueued-0" java.lang.NullPointerException
    I checked the url and it�s ok.
    Hope someone help.

    Well, I modified the getJarPath method to this:
    String getJarPath1(){
              String path=System.getProperty("java.class.path");
              for(int i=0;i<=path.length()-1;i++)
                   if(path.charAt(i)==';'){
                        return path.substring(0,i);
              return "";
         }Now I got the path I really need, for example:
    C:\Program Files\Eclipse\Workspace\myProject\images\pic.jpg
    Though, the picture is not loading. Here is what I am doing:
    String path=getJarPath1()+"\\images\\" + name + ".jpg";
    //path=C:\Program Files\Eclipse\Workspace\myProject\images\pic.jpg -> correct path
    URL u=null;
    try{
                 u = new URL(path);   //u is always null! why?
                }catch(MalformedURLException mf){}
    if(u!=null)
             try{
             icon = new ImageIcon(u);
             picture.setIcon(icon);
             }catch(Exception bla){}
             else {
             }What�s happening is that my "path" got the correct path, but when I put it in the URL it�s becoming null.
    The picture and the folder are in the correct place.
    I hope someone helps. Thx!

  • Loading images from a JAR

    Hi,
    My class is currently stored in a subdirectory of my JAR file, and in the directory with the class is a "textures" directory, containing all of my images.
    When I run my class from the directory before I zip it up to be a JAR, it works fine. But, as soon as I run it as a JAR file, it crashes when loading the images.
    Here's the code I'm using to load the images:
    BufferedImage temp = null;
    String path = this.getClass().getResource("textures/" + imagePath).toString();
    temp = ImageIO.read(new File(new URI(path)));What am I doing wrong?
    Thanks for any assistance! =)

    Hiii bro ,
    I think this will help u ,,,,,,,,
    suppose you have a folder Image , under that folder there are some image files and you have a main class say TestMain.class .
    In your main class(TestMain)
    import javax.swing.ImageIcon;
    Now write this code into your main class----------->
    public ImageIcon customOpenIcon = new ImageIcon(TestMain.class.getResource("/image/expanded.gif"));Thanks,
    sb

  • Need help with loading images in executable Jar

    Hi,
    I've developed an application using netbeans that needs to load and display images.
    I use netbeans Clean and Build function to create an executable Jar file. When I run the executable Jar file it runs fine but when I come to a section of the application that needs images it freezes and can't load the images.
    When I then return to netbeans the part of the program that did successfully run before Clean and Build doesn't work anymore and I get an error message saying Uncaught error fetching image:
    I use,
    URL url = getClass().getResource("images/image1.png");
    Image image1 = Toolkit.getDefaultToolkit().getImage(url);to load an image.
    Can someone tell me why, when I clean and build my project to create a JAR, my images fail to load.
    Should I be storing the images in a specific folder or something??
    Thanks

    I've opened the JAR using winzip and, for some reason, the JAR hasn't preserved my file structure. So, when I try to look for an image as follows:
    URL url = getClass().getResource("images/file1.png");
    Image img= Toolkit.getDefaultToolkit().getImage(url);The folder doesn't exist and so it can't find the image.
    Can someone tell me how to keep my file structure when I create the JAR or an alternative way to find the images within the JAR file.
    Cheers

  • Images not loading when I run my JAR

    I created a Yahtzee game that contains five die images. When I created the JAR file, I explicitly added the source and images to it. But when I go to run the app, no die images show up. I referenced Java's Creating a JAR File tutorial (http://java.sun.com/docs/books/tutorial/deployment/jar/build.html) but I didn't find anything useful regarding my issue.
    My Images folder is under my classes folder: Yahtzee\build\classes\Images
    I create the JAR from within classes and I add the die images that are in Images by using change directory option -C.
    jar cvfm Yahtzee.jar Manifest.txt *.class -C Images/ .
    I'm using the verbose option v, which allows me to see every file that gets added to the JAR, so I know there's no problem with missing files.
    Any thoughts?
    Message was edited by:
    d_mart

    By the way I'm adding the images into the JAR, they should be in its root.
    This is what I'm doing with my code. I have five die buttons that get a random die face, which are represented with my die images. I have an up-state (unselected) and a down-state (selected) image for each die face (1, 2, 3, 4, 5, 6). I have two different states because just like poker, you keep the cards that you want and disgard the ones that you don't want and in return, you get some random card for every card that you disgarded. So the selected and unselected images should be self-explanitory now. In Yahtzee, you have up to three rolls per hand, which I have a button that handles the rolls (<=3). I have stored my die images in a 2D array.
    My image file names are as follows:
    d1up.png, d1down.png, d2up.png, d2down.png,...d6up.png, d6down.png
    private Icon [][] dieImages;
    private Icon defaultDieImage;
    private Die [] dieButtons;
    // INITIALIZE DIE IMAGES
    defaultDieImage = new ImageIcon("../Yahtzee/src/Images/blank.png");
    dieImages = new ImageIcon[2][6];
    for(int i = 0; i <= 5; i++) {
         // up state images
         dieImages[0] = new ImageIcon("../Yahtzee/src/Images/d"
    + (i + 1) + "up.png");
    // down state images
    dieImages[1][i] = new ImageIcon("../Yahtzee/src/Images/d"
    + (i + 1) + "down.png");
    Those images are then loaded into the die buttons (depending on the roll).
    FYI, I just finished my 2nd semester of Java, so I'm still pretty new to the language and it's the only language that I know so far. With that said, please forgive for any dumb mistakes. It's all good though, I learn something new everyday. So you say that I should be using something like getClass().getClassLoader().getResource("an_image.jpg"); in my code instead of what I have?
    I hope the information that I provided helps.
    Dan

  • Doh! Why I need an applet to load an image on the web page???

    Hi everybody.
    I'm new student in Java programming and I try since to 1 week to understand, why Java applet is used to load image or something else on web page?
    Why not to use shockwave or flash to load an image or an animation?
    What is the difference?
    Best regards,
    Dimnet2000
    Canada

    The answer could be "why not ?"
    A better answer would be "it depends on what you want to do."
    If you simply want to display an image you should neither use Java nor Shockwave, plain html will be the best.
    If you want to do things like:
    - accessing a database
    - dynamically creating html
    - make an application accessible within the intranet of a company
    - make all at once
    - make other dynamic things
    Then Java is a good way to handle all these. Since it is a full programming language you can do more variable things than with shockwave which is fine for simple things that should look good.
    Btw.: If you want to train how to use Java on a html page displaying an image with Java is no bad idea. It gives a feeling on what you have to do when using Java.
    Hope this helps, Rommie.

Maybe you are looking for

  • Locking Issue in Planning DSO in SAP BW 7.3(Integrated Planning)

    Hi Experts, We have built Aggregation Level on Direct Update (planning enabled) DSO and used the same in the input ready queries.( Its complete Manual planning - new row addition feature in WAD). We have 5 characteristic and one key figure for planni

  • USB 3 external drive volume not mounting on restart

    I've bought an external USB 3 full size hard drive enclosure case and put in a 2TB drive. The drive is partitioned into 3 volumes. I've noticed from time to time that the volumes have gotten dismounted some how. If I unplug the USB cable and plug it

  • Os x 10.8.3 slow shutdown

    Since Mountain Lion my iMac shutdown (and startup) very slow. I already read that a lot of users have the samen problem. But I cannot find the solution of this problem. Also 10.8.3 don't solve this problem. Somebody can help?

  • How can I get my metronome click to work with 12/8 meter in Logic?

    I'm trying to get my KlopGeist click to 12/8 music. I can get it work with 4/4 and click on divisions set to 12th, but I cannot get truely 12/8. It's ok to recore, but the notation is different. Can anyone give me an answer? Thank you.

  • What are the pre instaled softwares in a macbook pro?

    pls let me know what are the pre instaled softwares in a mac? jose jacob