60% of the time Applet works every time...

It's as simple as this, my applet works in such random circumstances. It works for some people on Firefox, one on IE, but mostly for others it doesn't work. For me it works fine. I have all my images/class file/html file in the same location in the main folder for the site. Here's the code:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.lang.*;

import java.awt.image.*;

import javax.imageio.ImageIO;

import java.io.*;

import java.net.URL;

publicclass Driverextends JAppletimplements KeyListener, MouseListener, MouseMotionListener

{

int x,y;

Graphics bufferGraphics;

Image offscreen;

Dimension dim;

Toolkit kit = Toolkit.getDefaultToolkit();

publicboolean menu=true,ranks=false,beginRank=false,interRank=false,experRank=false,commaRank=false,jobs=false,interJob=false,experJob=false;

int[] pixels =newint[16 * 16];

Image mainMenu,rankMenu,beginner,inter,expert,command,jobMenu,interJobs,experJobs;

Image clearcursor = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));

Cursor transparentCursor =Toolkit.getDefaultToolkit().createCustomCursor(clearcursor,new Point(0, 0),"Transparent");

publicvoid init(){

addKeyListener(this);

addMouseListener(this);

addMouseMotionListener(this);

mainMenu=this.getImage(getCodeBase(),"main.jpg");

rankMenu=this.getImage(getCodeBase(),"mainRanks.jpg");

jobMenu=this.getImage(getCodeBase(),"mainJobs.jpg");

beginner=this.getImage(getCodeBase(),"beginnerRanks.jpg");

inter=this.getImage(getCodeBase(),"interRanks.jpg");

expert=this.getImage(getCodeBase(),"expertRanks.jpg");

command=this.getImage(getCodeBase(),"commandRanks.jpg");

interJobs=this.getImage(getCodeBase(),"interJobs.jpg");

experJobs=this.getImage(getCodeBase(),"expertJobs.jpg");

dim = getSize();

offscreen = createImage(dim.width,dim.height);

bufferGraphics = offscreen.getGraphics();

JRootPane rootPane = this.getRootPane();

rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

}

publicvoid paint(Graphics gr){

if(menu)

bufferGraphics.drawImage(mainMenu,0,0,this);

if(ranks)

bufferGraphics.drawImage(rankMenu,0,0,this);

if(beginRank)

bufferGraphics.drawImage(beginner,0,0,this);

if(interRank)

bufferGraphics.drawImage(inter,0,0,this);

if(experRank)

bufferGraphics.drawImage(expert,0,0,this);

if(commaRank)

bufferGraphics.drawImage(command,0,0,this);

if(jobs)

bufferGraphics.drawImage(jobMenu,0,0,this);

if(interJob)

bufferGraphics.drawImage(interJobs,0,0,this);

if(experJob)

bufferGraphics.drawImage(experJobs,0,0,this);

gr.drawImage(offscreen,0,0,this);

repaint();

}

publicvoid update(Graphics g){

paint(g);

}

publicvoid mousePressed(MouseEvent e){

}

publicvoid mouseReleased(MouseEvent e){

}

publicvoid mouseEntered(MouseEvent e){}

publicvoid mouseExited(MouseEvent e){

}

publicvoid mouseClicked (MouseEvent e){

x=e.getX();

y=e.getY();

// A bunch of meaningless if statements here that decide

// if when you click whether or not it will change images.

repaint();

}

publicvoid keyTyped(KeyEvent e){

int id = e.getID();

char c;

if (id == KeyEvent.KEY_TYPED){

c = e.getKeyChar();

if(c=='w'){

}

}

repaint();

}

publicvoid keyPressed(KeyEvent e){

}

publicvoid keyReleased(KeyEvent e){

}

publicvoid mouseDragged(MouseEvent e){

}

publicvoid mouseMoved(MouseEvent e){

x=e.getX();

y=e.getY();

repaint();}

publiclong pause(){

long time = System.currentTimeMillis();

while( System.currentTimeMillis() - time < 1000 ){};

return time;}

}

Can anyone tell me why/what I can do to make this applet work for everyone...or is just karma coming back at me for using applets in the first place?

[8232 byte] By [Rocksbaseballa] at [2007-11-26 19:07:16]
# 1
It might be useful to give us an idea of how it's not working.Just a thought, like.
itchyscratchya at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...
# 2
It's not starting for some people, the image loading doesn't work for others. They say that they see a gray box with a red x in the upper left corner. Usually I thought that red x=image problem, but the gray=wasn't init()'d.
Rocksbaseballa at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...
# 3
It might be useful to give us an idea of what error messages it's producing on the console.Just a thought, like.
itchyscratchya at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...
# 4
OR it's not, ever think of that? If it gave me an error message don't you think I would've started there?Just a thought, like.........
Rocksbaseballa at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...
# 5

OR it's not, ever think of that? If it gave me an error message don't you think I would've started there?

Plenty of people wouldn't, sadly.

So, you have no message in the status bar of the browser and nothing on the console? For a non-inited applet? Unusual, but fair enough.

Have you checked what JRE versions the clients are using? Have you looked at your HTML to see if that has any errors?

One thing you're not doing is using a MediaTracker to make sure your images are loaded before painting them. You may find it's easier to use ImageIcon than Image directly. You'll probably be best off packaging all the resources (images and class files) in a jar, using getClass().getResource(...) to get their classpath URLs, and then create ImageIcons which you can just draw using drawIcon(bufferGraphics, 0, 0).

Also note that the repaint() call at the end of your paint() method will cook your processor as it'll be running the paint loop as much as it possibly can.

And another thing, there's no need to do the offscreen rendering if the last painted image was the one you're now painting anyway. Come to think of it, if you're just painting images then all you're doing is painting them twice anyway, double buffering gives you no benefit there.

So, I would say use a tracker, or ImageIcon (which uses one implicitly), and check out the details of the users' environment if you can. And aure you sure there are no error messages anywhere? :o) ...if there aren't, you could add try/catch blocks in all your methods to print the stack for any uncaught runtime exceptions that might be occurring.

itchyscratchya at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...
# 6

The reason why i have double buffering going on in this applet is even though it's so simple now, I plan on adding some animation for it later. That way once in integrate it in there with what i have now, it won't be so hard to follow later. You're right though, double buffering right now is meaningless, lol. Those are some good ideas, I'll have to check into all of them. Thanks a lot, I'll throw some dukes your way.

Rocksbaseballa at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...
# 7

If there aren't any error messages, then I'd suggest adding some trace output to your applet, stuff that you know should produce output in the console. Then if your users say it doesn't work, you can either:

1) at least get some indication what's going on and where, from the trace output

2) determine that things are so messed up that basic I/O isn't working (suggesting that maybe their Java install is messed up, perhaps)

3) suspect that maybe your users don't know how to read the error messages properly...and in fact there were error messages all along, they just weren't reporting them.

paulcwa at 2007-7-9 20:59:28 > top of Java-index,Desktop,Core GUI APIs...