gpt4 book ai didi

java - 无法找到或加载主类cmd

转载 作者:行者123 更新时间:2023-12-01 19:08:35 25 4
gpt4 key购买 nike

我用 javac 编译了一些示例代码,当我尝试运行它时,我得到的是:

C:\Users\Lenis>cd C:\Java\2D

C:\Java\2D>java donut.board
Error: Could not find or load main class donut.board

我尝试编写“java -cp . donut.board”,但仍然得到相同的结果。

我的类路径是:“C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar;。”

如何解决?

这是代码:

package donut;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import javax.swing.JPanel;

public class Board extends JPanel{

public void paint(Graphics g)
{
super.paint(g);

Graphics2D g2 = (Graphics2D) g;

RenderingHints rh =
new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);

g2.setRenderingHints(rh);

Dimension size = getSize();
double w = size.getWidth();
double h = size.getHeight();

Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
g2.setStroke(new BasicStroke(1));
g2.setColor(Color.gray);


for (double deg = 0; deg < 360; deg += 5) {
AffineTransform at =
AffineTransform.getTranslateInstance(w / 2, h / 2);
at.rotate(Math.toRadians(deg));
g2.draw(at.createTransformedShape(e));
}
}
}

最佳答案

类中没有 main 方法,并且在调用时必须给出 donut.Board(大写 B),它区分大小写。添加主要方法。

关于java - 无法找到或加载主类cmd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9191574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com