Why doesn't my applet work on Mac?

This works fine for me on Windows, but someone with a Mac tested it and said that they just got a black screen, although they could hear their character moving. repaint() is definitely being called but it isn’t doing it…

Strangely, on a Mac I have (it’s an old PowerPC one with Java 1.5 and OS X 10.4), I get a black screen too but if I resize the browser window or move another window on top of it, it starts working.

    public void init() {
        setBackground(Color.black);
        log("Setting up");
        //Initialize the canvas, set up input listeners
        log("Starting animator");
        animator = new Thread(this);
        animator.setName("AnimatorThread");
        animator.start();

        new Thread(new Runnable()
        {
            public void run()
            {

                setIgnoreRepaint(true);
                //load some stuff
                setIgnoreRepaint(false);

                doneLoading = true;
            }
        }).start();
    }
    @Override
    public void start()
    {
    }
    @Override
    public void update(Graphics g)
    {
        canvas.repaint(); //Updates a VolatileImage stored in the Canvas class
        g.drawImage(canvas.getImage(), 0, 0, this);
    }
    @Override
    public void paint(Graphics g)
    {
        update(g);
    }
    public void run()
    {
        log("Current thread is "+Thread.currentThread());
        while(Thread.currentThread() == animator)
        {
            //Process input and so on
            repaint();
            try {
                Thread.sleep(8); //limit FPS
            } catch (InterruptedException ex) {
            }
        }
    }

I’ve tried moving code around between init() and start() and paint() and update(), no success.

Anyone see a problem?

Edit: Fixed some code that was copied incorrectly

Update: someone with Windows 7 had the problem too.

Why not put it online somewhere so I can test it and see what happens?

its from the cubic realms thread in the showcase, here is the link
http://1scripts.net/cubic/game.php

its a good idea to call validate() at the end of you init code.

looking at your code, you should call it after your Thread has finished loading.

Here it is: http://1scripts.net/cubic/game.php?version=CubicRealms0.06_old.jar

After posting this I decided to try remaking the game as a JApplet with graphics drawn on a JPanel just to see what happened; here is the new one: http://1scripts.net/cubic/game.php

Although the loading screen didn’t work on my Mac (it’s an old one, maybe the loading takes so much CPU so the graphics thread is getting starved?), I didn’t have to resize the window to get it to work, which seems like a good sign.

I had someone with Win7 test the JApplet version and it worked for them, although they hadn’t tried the old version.

Works fine on my Mac.

It’s 2D Minecraft! :slight_smile: