Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Codebase in applet not working after Java update 7-25

 
Paul Greenstock
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the latest update the following code no longer retrieves my gifs. I did read that the latest update has changed codebase to return null. The question is how to fix this. I am not using a jar, I just have the class and gifs and html in the same folder. The applet paints the screen and just sits, no error messages on the console. Can I hard code the codebase in my applet ??


public void getimages() {
int z = 0;
String filename = "";
String suffix=".gif";
String suits[] = { "h", "d", "s", "c" };
String cards[] = { "a", "2", "3", "4", "5", "6", "7", "8", "9", "t",
"j", "q", "k" };
gifs[z] = getImage(this.getCodeBase(), "b" + suffix);
gifs[53] = getImage(this.getCodeBase(), "j" + suffix);
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 13; y++) {
z++;
filename = cards[y].concat(suits[x]).concat(suffix);
gifs[z] = getImage(this.getCodeBase(), filename);
}
}
}
 
Regina Thomas
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quickly checking the code- did you insure the gif files were located where the class file for the applete was located.. Are you using a JAR?

Q...
 
Paul Greenstock
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. And this worked perfectly until the latest update. And I'm not using a Jar.
 
Regina Thomas
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could never get that code to work while testing in my IDE-- I juse Borland and Netbeans... no matter the version of of the sdk... that said -- I can use getcodebase outside of the IDE environment.. I think I had a problem with getimage and getcodebase used together within the IDEs. I also have not updated my version of Java.. so thank you for the heads up.

Q...
 
Paul Greenstock
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regina, this code works (but I dont like hardcoding the folder name)

public void getimages() {
String path = "file:////f:/towers/";
String fullpath="";
int z = 0;
String suffix=".gif";
String suits[] = { "h", "d", "s", "c" };
String cards[] = { "a", "2", "3", "4", "5", "6", "7", "8", "9", "t",
"j", "q", "k" };
try {
fullpath = path.concat("b"+suffix);
gifs[z] = getImage(new URL(fullpath));
fullpath = path.concat("j"+suffix);
gifs[53] = getImage(new URL(fullpath));
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 13; y++) {
z++;
fullpath = path.concat(cards[y]).concat(suits[x]).concat(suffix);
gifs[z] = getImage(new URL(fullpath));
}
}
} catch (Exception MalformedURLexception) {
System.out.println("MalformedURLexception");
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic