plz reply to my web id my web id is <EMAIL SNIPPED>
plzhelp me
import java.io.*;
import java.applet.*;
import java.awt.*;
class crystal extends Applet
{ private crystalGrid crystal;
private Button reset, stop, go, moreRows, fewerRows, moreCols, fewerCols;
public void init()
{ reset = new Button("Randomize");
add(reset);
stop = new Button("Stop");
add(stop);
go = new Button("Go");
add(go);
moreRows = new Button("More rows");
add(moreRows);
fewerRows = new Button("Fewer rows");
add(fewerRows);
moreCols = new Button("More columns");
add(moreCols);
fewerCols = new Button("Fewer columns");
add(fewerCols);
setBackground(Color.cyan);
Graphics g = getGraphics();
crystal = new crystalGrid(g);
crystal.setRandomValues();
crystal.start();
}
public boolean action (Event e, Object arg)
{ if (e.target == reset)
crystal.setRandomValues();
if (e.target == stop)
crystal.keepGoing = false;
if (e.target == go)
crystal.keepGoing = true;
if (e.target == moreRows)
crystal.addARow();
if (e.target == fewerRows)
crystal.deleteARow();
if (e.target == moreCols)
crystal.addACol();
if (e.target == fewerCols)
crystal.deleteACol();
return true;
}
}
public class crystalGrid extends Thread
{ private int v[][];
private int numColours = 12;
final int maxRows = 101;
final int maxCols = 101;
private int numRows = maxRows, numCols = maxCols;
public boolean keepGoing = true;
private Graphics g;
public crystalGrid (Graphics graphics)
{ g = graphics;
v = new int[maxCols][maxRows];
setRandomValues();
}
// Set the contents of the grid to random numbers
public void setRandomValues()
{ for (int i = 0; i < numCols; i++)
for (int j = 0; j < numRows; j++)
v[i][j] = (int)(Math.random() * numColours);
}
public void display (Graphics g)
{ for (int i = 0; i < numCols; i++)
for (int j = 0; j < numRows; j++)
{ setColour(g,v[i][j]);
g.fillRect(i*3+10,j*3+30,3,3);
}
}
public void setColour(Graphics g, int n)
{ switch(n)
{ case 0 : g.setColor(Color.black); break;
case 1 : g.setColor(Color.lightGray); break;
case 2 : g.setColor(Color.yellow); break;
case 3 : g.setColor(Color.green); break;
case 4 : g.setColor(Color.blue); break;
case 5 : g.setColor(Color.white); break;
case 6 : g.setColor(Color.magenta); break;
case 7 : g.setColor(Color.orange); break;
case 8 : g.setColor(Color.pink); break;
case 9 : g.setColor(Color.darkGray); break;
case 10 : g.setColor(Color.gray); break;
case 11 : g.setColor(Color.red); break;
}
}
// This causes the crystal to move on one step
public void moveOnAStep ()
{ int i,j,m,n,x,y;
// Use v2[][] as a temporary grid
int v2[][] = new int[maxCols][maxRows];
for (i = 0; i < numCols; i++)
for (j = 0; j < numRows; j++)
{ v2[i][j] = v[i][j]; // Assume there is no change by default
for (m = i-1; m <= i+1; m++)
for (n = j-1; n <= j+1; n++)
{ x = (m + numCols) % numCols; // Implements a "round the world" effect
y = (n + numCols) % numCols;
if (v[x][y] == (v[i][j] + 1) % numColours)
v2[i][j] = (v[i][j] + 1) % numColours; // If it can, move one one step
}
}
// Now copy the v2 grid back to v
for (i = 0; i < numCols; i++)
for (j = 0; j < numRows; j++)
v[i][j] = v2[i][j];
}
// Add a row if the current number of rows is less than the maximum number
public void addARow ()
{ if (numRows < maxRows)
{ numRows++;
for (int i = 0; i < maxCols; i++)
v[i][numRows-1] = (int)(Math.random() * numColours); // -1 as the index starts from 0
}
}
// Delete a row if the current number of rows is greater than 10
public void deleteARow ()
{ if (numRows > 10)
{ numRows--;
g.setColor(Color.cyan); // Remove unwanted row from display
for (int i = 0; i < numCols; i++)
g.fillRect(i*3+10,numRows*3+30,3,3);
}
}
// Add a column if the current number of rows is less than the maximum number
public void addACol ()
{ if (numCols < maxCols)
{ numCols++;
for (int j = 0; j < maxRows; j++)
v[numCols - 1][j] = (int)(Math.random() * numColours); // -1 as the index starts from 0
}
}
// Delete a row if the current number of cols is greater than 10
public void deleteACol ()
{ if (numCols > 10)
{ numCols--;
g.setColor(Color.cyan); // Remove unwanted row from display
for (int j = 0; j < numRows; j++)
g.fillRect(numCols*3+10,j*3+30,3,3);
}
}