This problem has puzzled me for nearly three days...
As I don't know even this kind of thing would happen at the first place...
About how to display the picture, if i write the related codes like this:
aquariumImage = Toolkit.getDefaultToolkit().getImage("bubbles.gif");
it can be run well in the eclipse but in the jar.
so I change it into this by adding URL :
URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);
it then works perfectly.
import
java.awt.
*
;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
public class Test extends Frame
... {
private static final long serialVersionUID = 1L;
static Image aquariumImage;
public Test()
...{
addWindowListener(new WindowAdapter()
...{
public void windowClosing(WindowEvent e)
...{
dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
...{
Test test = new Test();
test.go();
test.setSize(600, 435);
test.setVisible(true);
Graphics g = test.getGraphics();
while (!g.drawImage(aquariumImage, 0, 0, test));
}
public void go()
...{
URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
public class Test extends Frame
... {
private static final long serialVersionUID = 1L;
static Image aquariumImage;
public Test()
...{
addWindowListener(new WindowAdapter()
...{
public void windowClosing(WindowEvent e)
...{
dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
...{
Test test = new Test();
test.go();
test.setSize(600, 435);
test.setVisible(true);
Graphics g = test.getGraphics();
while (!g.drawImage(aquariumImage, 0, 0, test));
}
public void go()
...{
URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);
}
}