timmay3141
Programmer
I'm trying to make an applet draw some dice images. The images are in files named die1.png through die6.png. Here's my code for loading and displaying them:
[source]
public void loadImages() {
for(int i = 0; i < 6; i++) {
URL imageUrl = getClass().getResource("/die" + (i+1) + ".png");
diceImages = Toolkit.getDefaultToolkit().getImage(imageUrl);
}
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
// draw the dice
for(int i = 0; i < 5; i++) {
g2.drawImage(diceImages[dice - 1], 40 * i + 50, 75, this);
}
}
[/source]
By the way, this is using swing, not AWT if it matters. I'm using eclipse to run this as an applet, and it works fine on my computer. However, when I load it on to the net, the images don't show up. I'm inexperienced debugging applets in Java - I have debugged applications enough in C++ and C#, but debugging applets seems to be trickier. Any tips for debugging applets in general would be appreciated.
[source]
public void loadImages() {
for(int i = 0; i < 6; i++) {
URL imageUrl = getClass().getResource("/die" + (i+1) + ".png");
diceImages = Toolkit.getDefaultToolkit().getImage(imageUrl);
}
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
// draw the dice
for(int i = 0; i < 5; i++) {
g2.drawImage(diceImages[dice - 1], 40 * i + 50, 75, this);
}
}
[/source]
By the way, this is using swing, not AWT if it matters. I'm using eclipse to run this as an applet, and it works fine on my computer. However, when I load it on to the net, the images don't show up. I'm inexperienced debugging applets in Java - I have debugged applications enough in C++ and C#, but debugging applets seems to be trickier. Any tips for debugging applets in general would be appreciated.