【发布时间】:2015-11-23 14:13:25
【问题描述】:
我想运行一个小程序文件,而不需要在 CMD 中创建两个单独的文件,即 .html 和 .java 文件。 html代码嵌入到java代码中。
当我为 html 文件创建不同的文件并运行它时,我尝试使用 appletviewer ColorDemo 和 appletviewer ColorDemo.html 运行它,它工作正常。
This is the error I am getting while running the code.
这是我一直试图通过 cmd 运行的代码。
// Demonstrate color.
import java.awt.*;
import java.applet.*;
//html embedded in applet
/*
<applet code="ColorDemo" width=300 height=200>
</applet>
*/
public class ColorDemo extends Applet {
// draw lines
public void init()
{
setBackground(Color.yellow);
}
public void paint(Graphics g) {
Color c1 = new Color(255, 0, 0);
Color c2 = new Color(100, 255, 100);
Color c3 = new Color(100, 100, 255);
g.setColor(c1);
g.drawLine(0, 0, 100, 100);
g.drawLine(0, 100, 100, 0);
g.setColor(c2);
g.drawLine(40, 25, 250, 180);
g.drawLine(75, 90, 400, 400);
g.setColor(c3);
}
}
【问题讨论】:
-
嗨@Savin,很高兴见到你!检查您的程序正在查找的文件确实是否存在。因为
it could not find the file specified -
yes @xameeramir 它显示为“找不到指定的文件”,但 .class 文件存在于给定位置。
-
1) 请学习如何从命令行(DOS)复制文本它对搜索引擎和我们都更有用。 2)
appletviewer ColorDemo.html应该是appletviewer ColorDemo.java以便以您需要的方式启动小程序。这就是example on the applet info. page 的工作方式(参见类声明之前的 cmets)。
标签: java html cmd compilation applet