0

Can't figure out the error message this gives me when I try to run the class

When I attempt to run the class, I get the following error code:

Error: Could not find or load main class sun.applet.AppletViewer
Caused by: java.lang.ClassNotFoundException: 
    sun.applet.AppletViewer

I have included the entire class and all of its components.

I have gotten this exact same code to function perfectly in jGrasp, but I'm trying to make the jump to intelliJ, and I can't figure out why I get this error code with the same exact code. I am well aware that the Applet method/class is deprecated, and it doesn't seem to matter in jGrasp.

FYI: The aim of the code is to create an applet that draws a bunch of things from scratch, not to draw an actual image.

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);
}
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
gaelbrax
  • 1
  • 3
  • Possible duplicate of [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – George Z. Mar 07 '19 at 19:40
  • 2
    Applets has been removed from Java 9 and higher (and thus the AppletViewer). You can only use applets on Java 8. Anyway you shouldn't start riding a dead horse, throw away the applet code and start over new. – Robert Mar 07 '19 at 19:45
  • 1) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/moving-to-a-plugin-free-web). 2) A single blank line of white space in source code is all that is *ever* needed. Blank lines after `{` or before `}` are also typically redundant. – Andrew Thompson Mar 08 '19 at 15:15

0 Answers0