PDA

Click to See Complete Forum and Search --> : Applet Problems


GamerMax5
Oct 13th, 2006, 07:42 PM
Wow. It's been a while since I last posted here. ^_^

Anywho, I'm writing an applet that will act as a type of dynamice blog for my site. I realize this could be better done in Flash but when you have a POS computer like mine, Applets are the alternative. :blush:

Here is the code I have so far. This is very basic and there isn't a whole lot being displayed here but I'm still developing it.

import java.applet.*;
import java.awt.*;

public class BlogApplet extends Applet{
Font blogFont;
String[] colorState = new String[5];
String currentColorState;
Image[] iconsBlue = new Image[4];

public void init(){
blogFont = new Font("Tahoma", Font.BOLD, 12);
colorState[0] = "Blue";
colorState[1] = "Green";
colorState[2] = "Magenta";
colorState[3] = "Orange";
colorState[4] = "Yellow";
iconsBlue[0] = getImage(getCodeBase(), "computer_24Blue.gif");
iconsBlue[1] = getImage(getCodeBase(), "documents_24Blue.gif");
iconsBlue[2] = getImage(getCodeBase(), "home_24Blue.gif");
iconsBlue[3] = getImage(getCodeBase(), "mail_24Blue.gif");
currentColorState = colorState[0];
}

public void start(){}

public void stop(){}

public void destroy(){}

public void paint(Graphics g){
g.setFont(blogFont);
g.drawString(this.currentColorState, 10, 10);
g.drawImage(iconsBlue[0], 0, 0, this);
}
}

My problem is that the compiler doesn't mark it as a problem, so apparently it isn't, but the last line in the paint method must not be working or it's working and not displaying the image I tell it to because when the applet loads, it displays the current color setting (the g.drawString) but the image is no where to be found in my applet. Medic please! :D Thanks in advance!

ComputerJy
Oct 14th, 2006, 03:33 AM
There is only one reason why your applet wouldn't show images. They don't exist

If you are using an IDE make sure the images are in the correct place, because the getCodeBase() returns the URL of the code attribute from the <applet> tag

GamerMax5
Oct 15th, 2006, 05:19 PM
It's working fine now. The images were there. I think it's my computer. It doesn't like to cooperate all the time, mainly because it's ancient but I have to make do with what I have so... :D

Thanks for the help!