当我尝试运行该类时,无法弄清给我的错误消息
当我尝试运行该类时,出现以下错误代码:
Error: Could not find or load main class sun.applet.AppletViewer
Caused by: java.lang.ClassNotFoundException:
sun.applet.AppletViewer
我包括了整个班级及其所有组成部分。
我已经获得了完全相同的代码,可以在jGrasp中完美运行,但是我试图跳转到intelliJ,我不知道为什么我会得到具有相同完全代码的错误代码。我很清楚Applet方法/类已被弃用,并且在jGrasp中似乎无关紧要。
仅供参考:该代码的目的是创建一个applet,该applet从头开始绘制一堆东西,而不是绘制实际图像。
import java.awt.*;
import java.applet.*;
import java.util.*;
@SuppressWarnings("deprecated")
public class ree extends Applet
{
int width, height;
Random rand = new Random();
public void init()
{
width = getSize().width;
height = getSize().height;
}
@Override
public void paint(Graphics g)
{
// Draw Grid
g.drawRect(10,10,780,580);
g.drawLine(400,10,400,590);
g.drawLine(10,300,790,300);
// Draw Random Lines
for (int i = 0; i < 100; ++i)
{
int x1 = rand.nextInt(400); //int x1 = rand.nextInt(maxvalue); creates a random point on applet with value no greater than 400
int y1 = rand.nextInt(300);
int x2 = rand.nextInt(400);
int y2 = rand.nextInt(300);
float r = rand.nextFloat(); //creates a new color
float gr = rand.nextFloat();
float b = rand.nextFloat();
Color randomColor = new Color (r,gr,b);
g.setColor(randomColor);
g.drawLine(x1,y1,x2,y2);
}
// Draw Random Squares
for (int i = 0; i < 100; ++i)
{
int sx1 = rand.nextInt(350)+400;
int sy1 = rand.nextInt(250);
float sr = rand.nextFloat();
float sgr = rand.nextFloat();
float sb = rand.nextFloat();
Color squareColors = new Color (sr, sgr, sb);
g.setColor(squareColors);
g.fillRect(sx1, sy1, 50, 50);
}
// Draw Random Circles
for (int i = 0; i < 100; ++i)
{
int cx1 = rand.nextInt(300);
int cy1 = rand.nextInt(225)+300;
int dim = rand.nextInt(100);
float cr = rand.nextFloat();
float cgr = rand.nextFloat();
float cb = rand.nextFloat();
Color circleColors = new Color (cr, cgr, cb);
g.setColor(circleColors);
g.drawOval(cx1, cy1, dim, dim);
}
// Draw 3-D Box
Polygon leftSide = new Polygon();
leftSide.addPoint(600, 400);
leftSide.addPoint(600, 500);
leftSide.addPoint(550, 450);
leftSide.addPoint(550, 350);
g.setColor(Color.GREEN);
g.fillPolygon(leftSide);
Polygon backSide = new Polygon();
backSide.addPoint(600, 400);
backSide.addPoint(550, 350);
backSide.addPoint(650, 350);
backSide.addPoint(650, 400);
g.setColor(Color.YELLOW);
g.fillPolygon(backSide);
Polygon rightSide = new Polygon();
rightSide.addPoint(700, 400);
rightSide.addPoint(650, 400);
rightSide.addPoint(650, 350);
g.setColor(Color.BLUE);
g.fillPolygon(rightSide);
g.setColor(Color.RED);
g.fillRect(600, 400, 100, 100);
}
}