Reputation: 21
Hey guys i wanted some help with a pokemon game that I am making for a final project. I wanted to create a map that paints images to the screen based on a random variable. The class compiles but when I run the applet in applet viewer it says "Start: applet not initialized" I have no idea what's wrong.
import java.awt.*;
import java.applet.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.util.*;
import java.util.ArrayList;
import java.awt.Image.*;
class map extends JApplet
{
Image grass;
Image Sgrass;
Image sand;
Image[][] gr = new Image[10][10];
public void init()
{
grass = getImage(getCodeBase(),"Grass.jpg");
Sgrass = getImage(getCodeBase(),"Non-Grass.jpg");
sand = getImage(getCodeBase(),"Sand.jpg");
grid();
}
public void grid()
{
for(int i = 0; i<10; i++)
{
for(int j = 0; j<10; j++)
{
double x = Math.random();
if(x<=0.70)
{
gr[i][j] = grass;
}
else if(x>0.70 && x<=0.90)
{
gr[i][j] = Sgrass;
}
else if (x>0.90)
{
gr[i][j] = sand;
}
}
}
}
public void paint(Graphics g)
{
int a = 0;
int b = 0;
while(b<=500)
{
while(a<=500)
{
for(int z = 0; z<10; z++)
{
for(int w = 0; w<10; w++)
{
g.drawImage(gr[z][w],a,b,50,50,this);
a+=50;
}
}
}
b+=50;
a = 0;
}
}
}
Upvotes: 2
Views: 55
Reputation: 9946
The only problem i can see with your code is your class is not public and until it is public (it will have default access) other classes in another package can not access it. For example while running it the class sun.applet.AppletPanel
will not be able to access it.
So change your class declaration to
public class map extends JApplet {
Upvotes: 2