我編譯javac的一些示例代碼,當我試圖跑這裏這就是我得到:「java命令donut.board」無法找到或加載主類CMD
C:\Users\Lenis>cd C:\Java\2D
C:\Java\2D>java donut.board
Error: Could not find or load main class 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));
}
}
}
行爲雖然該鏈接可以回答這個問題,最好是包括的主要部分在這裏回答並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Rick 2015-03-11 17:32:00
@瑞克感謝您的評論,我會添加一些代碼來改善答案:) – salembo 2015-03-11 18:50:42