I have this code:
When I try to run it in the Netbeans Apllet Viewer, I get this error message:package zombies; import java.applet.*; import java.awt.*; import java.awt.event.*; /** * * @author */ class ZOMBIE extends Applet implements Runnable, MouseListener { //var declaration private Thread th;//thread private Image dbImage;//image for double buffering private Graphics dbg;//grpahics for double buffering private int radius;//player circle radius private int x_pos;//player x position private int y_pos;//player y position private int mX;//mouse click x postion private int mY;//mouse click y position private int Radius;//zombie circle radius private int num5;//player melee strength private int num6;//zombie strength private boolean infected;//player infected boolean //var declaration //class declaration class zombie{ boolean chase = false;//zombie chase boolean int X_pos = (int)Math.random()*500;//zombie x position int Y_pos = (int)Math.random()*500;//zombie y position int sX_pos = X_pos;//zombie start x position int sY_pos = Y_pos;//zombie start y position int Zx;//zombie destination x position int Zy;//zombie destination y position int num1 = 0;//timer var number one int num2 = 0;//timer var number 2 double num3;//random offset x position double num4;//random offset y position } //class declaration //object declaration zombie z; //object declaration //functions public void init(){ //initialize vars infected = false; num5 = 0; num6 = 0; radius = 10; z.X_pos = 100; z.Y_pos = 100; z.Zx = z.X_pos; z.Zy = z.Y_pos; z.sX_pos = z.X_pos; z.sY_pos = z.Y_pos; x_pos = 250; y_pos = 250; mX = 250; mY = 250; Radius = 10; //repeated vars //repeated vars //initialize vars //set the stage this.setSize(500, 500); setBackground(Color.LIGHT_GRAY); addMouseListener(this); //set the stage } public void start(){ //start thread th = new Thread(this); th.start(); } public void run(){ //running code Thread.currentThread().setPriority(Thread.MAX_PRIORITY); while(true){ //paint graphics repaint(); //paint graphics //game engine //end game code if(infected == true){ mX = x_pos; mY = y_pos; } //end game code //player movement code if(y_pos < mY){ y_pos++; } if(y_pos > mY){ y_pos--; } if(x_pos < mX){ x_pos++; } if(x_pos > mX){ x_pos--; } //player movement code //player detection (by zombie) if(Math.abs(z.X_pos - x_pos)<50 && Math.abs(z.Y_pos - y_pos)<50){ z.chase=true; } if(Math.abs(z.X_pos - x_pos)>100 && Math.abs(z.Y_pos - y_pos)>100){ z.chase = false; } //player detection (by zombie) //zombie chase code if(z.chase==true){ z.Zx = x_pos; z.Zy = y_pos; z.sX_pos = z.X_pos; z.sY_pos = z.Y_pos; } //zombie chase code //zombie movement timer (timer number one) if(z.num1>0){ z.num1--; } if(z.num1==0){ //zombie movement code if(infected == false){ if(z.Y_pos < z.Zy){ z.Y_pos++; if(z.chase==true){ z.Y_pos++; } } if(z.Y_pos > z.Zy){ z.Y_pos--; if(z.chase==true){ z.Y_pos--; } } if(z.X_pos < z.Zx){ z.X_pos++; if(z.chase==true){ z.X_pos++; } } if(z.X_pos > z.Zx){ z.X_pos--; if(z.chase==true){ z.X_pos--; } } } z.num1 = 2; if(z.chase==false){ z.num1 += 2; } //zombie movement code } //zombie movement timer (timer number one) //zombie idle movement code if(z.chase == false){ //idle wandering code timer (timer number two) if(z.num2>0){ z.num2--; } if(z.num2==0){ //generate random offset z.num3 = Math.random() * 15 - Math.random() * 15; z.num4 = Math.random() * 15 - Math.random() * 15; //generate random offset System.out.print(z.sX_pos + " "); z.Zx = z.sX_pos + (int)z.num3; z.Zy = z.sY_pos + (int)z.num4; z.num2 = 100; } //idle wandering code timer (timer number two) } //zombie idle movement code try{ Thread.sleep(20); }catch(InterruptedException ex){ } Thread.currentThread().setPriority(Thread.MIN_PRIORITY); //game engine } } public void paint(Graphics g){ //graphics code g.setColor(Color.white); if(Math.abs(z.X_pos - x_pos)<10 && Math.abs(z.Y_pos - y_pos)<10){ g.setColor(Color.pink); num6++; if(num5<num6 && infected == false){ g.setColor(Color.red); infected = true; }else if(num5>num6){ //z = null; } if(infected == true){ g.setColor(Color.darkGray); } } if(infected == true){ g.setColor(Color.darkGray); } g.fillOval(x_pos - radius,y_pos - radius,radius,radius); g.setColor(Color.darkGray); if(Math.abs(z.X_pos - x_pos)<10 && Math.abs(z.Y_pos - y_pos)<10){ g.setColor(Color.red); } g.fillOval(z.X_pos - Radius,z.Y_pos - Radius,Radius,Radius); //graphics code } public void update(Graphics g){ //double buffering if(dbImage==null){ dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); g.drawImage(dbImage, 0, 0, this); //double buffering } public void mouseClicked (MouseEvent e){ //nothing here } public void mousePressed(MouseEvent e) { //event listener code mX = e.getX(); mY = e.getY(); //event listener code } public void mouseReleased(MouseEvent e) { //nothing } public void mouseEntered(MouseEvent e) { //nothing } public void mouseExited(MouseEvent e) { //nothing } }
Start: applet not initialized.