【问题标题】:How to run a applet without making two separate file i.e .html and .java file in CMD. The html code is embedded into java code如何在不创建两个单独的文件(即 CMD 中的 .html 和 .java 文件)的情况下运行小程序。 html代码嵌入到java代码中
【发布时间】:2015-11-23 14:13:25
【问题描述】:

我想运行一个小程序文件,而不需要在 CMD 中创建两个单独的文件,即 .html 和 .java 文件。 html代码嵌入到java代码中。

当我为 html 文件创建不同的文件并运行它时,我尝试使用 appletviewer ColorDemoappletviewer 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


【解决方案1】:

我不是java zen。但是,根据您所指的错误:

  • 检查您的程序正在查找的文件确实存在。因为it could not find the file specified

  • 检查是否为some privilege issue

【讨论】:

  • no Zameer @xameeramir,如果您阅读整个错误字符串,您会发现 IO 异常,这不是主要错误。类文件已经存在于指定的目录中。
  • 嗯,因为安全原因,我见过很多IO exceptions。也许这个答案中的假设是错误的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-30
  • 2011-09-21
  • 2011-08-08
  • 1970-01-01
  • 2020-04-17
  • 2023-02-04
  • 2011-01-30
相关资源
最近更新 更多