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);
     }
  }

Dani AI

Generated

This is an old AWT applet that uses the pre‑1.1 event model and some APIs that are now deprecated. The compiler warning is a diagnostic, not a fatal error; run the compiler with deprecation diagnostics to see exactly which calls are triggering the message (for example, javac -deprecation MySource.java). As pointed out, those diagnostics point to the exact deprecated methods to replace.

Two practical compilation/runtime issues seen in the thread: class visibility and the outdated event model. The applet entry class needs to be a public top‑level class and the source filename must match any public class it contains (this is the point was making — also follow Java naming conventions to avoid confusion between crystal and crystalGrid). Keeping an applet class non‑public or misnaming the file will produce access/compile errors in addition to warnings.

Modernize the listeners and drawing. Replace the deprecated action(Event,Object) old‑style handler with ActionListener on each Button; example wiring:

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

reset.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        crystal.setRandomValues();
    }
});

Avoid holding a Graphics object obtained once via getGraphics(); override paint (AWT) or paintComponent (Swing) and call repaint() to trigger redraws. For animation prefer a Swing Timer (or a background thread that updates state and calls repaint() on the EDT).

A logic bug to fix while modernizing: the grid wrap for the Y coordinate uses numCols in the modulo where it should use numRows — that will break wrapping when rows and columns differ. Last note: applets are obsolete in modern Java/browsers; for long‑term compatibility migrate this code to a standalone Swing/JFrame or JavaFX application and use the modern event/drawing patterns described above.

Recommended Answers

All 2 Replies

That deprecated warning also tells you what you should done (i.e. recompile with the -Xlint:deprecated option). Have you done that?

..And what ?

the 'crystal' class has to be public if you want to use it as an applet

public class crystal {
...

(and please, respect naming conventions, such as uppercase letters for class names, etc..)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.