WILLYB
WILLYB

Reputation: 15

My code says that the applet is not initialized

I'm trying to make a simple math game, but right now i'm just trying to see if the code will even run, and so far it doesn't :(. It doesn't give me any actual errors on the task view but wen the applet window opens it says that the applet is not initialized. Would appreciate any help.

import java.awt.*;
import java.applet.*;
import javax.swing.*;

public class Java_Math_Game extends Applet {


    Image offScreen;
    Graphics offG;

    Image background, pic;
    AudioClip sound;

    int picX, picY, picWidth, picHeight;

    public void init() {
        offScreen = createImage(500,500);
        offG = offScreen.getGraphics();

        background = getImage(getCodeBase(),"range.jpg" );

        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(background, 0);
        tracker.addImage(pic, 0);
        while(tracker.checkAll(true) != true){ }
        if (tracker.isErrorAny()){
            JOptionPane.showMessageDialog(null, "Trouble loading pictures.");
        }

        offG.drawImage(background, 0, 0, this);
        picX = 50;
        picY = 350;
        offG.drawImage(pic, picX, picY, this);

        picWidth = pic.getWidth(this);
        picHeight = pic.getHeight(this);
    }


    public void paint(Graphics g) {
        g.drawImage(offScreen,0,0,this);
    }
}

Upvotes: 0

Views: 67

Answers (1)

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

There should be a console somewhere displaying an exception stack trace. For instance pic is dereferenced but never assigned so will throw a NullPointerException if there aren't any earlier problems.

However, Java Applets were removed from Java SE 11 and really shouldn't be used.

Upvotes: 2

Related Questions