Java: как использовать графику в intellij? - PullRequest
0 голосов
/ 07 марта 2019

Не могу понять, какое сообщение об ошибке выдает мне, когда я пытаюсь запустить класс

Когда я пытаюсь запустить класс, я получаю следующий код ошибки:

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

Я включил весь класс и все его компоненты.

Я получил этот точно такой же код для идеального функционирования в jGrasp, но я пытаюсь перейти к intelliJ, и я не могу понять, почему я получаю этот код ошибки с таким же точным кодом.Мне хорошо известно, что метод / класс Applet устарел, и в jGrasp это не имеет значения.

К вашему сведению: цель кода - создать апплет, который рисует кучу вещей с нуля, а не рисовать реальное изображение.

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