【问题标题】:html not appearing for Applethtml 没有出现在 Applet 中
【发布时间】:2016-06-21 22:14:57
【问题描述】:

我尝试为我的小程序创建一个 html 文件,但没有显示任何内容。

这是我的小程序的代码

public class TimeSet extends Applet{

    public TimeSet(){
        //set the title
        frame = new JFrame();
        frame.setTitle("2 hour time set");

        //specify what happens when the close button is clicked
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //set main panel where all other panels will exist in
        mainPanel = new JPanel(new GridLayout(4,1));
        add(mainPanel);

        timePanel();
        ammountPanel();
        durationPanel();
        buttonSet();

        setVisible(true);

    }

这是我用于 htm 的代码

<Html>
<Head>
<Title>TimeSet</Title>
</Head>

<Body>
<Applet Code="TimeSet.class" width=200 Height=100>
</Applet>
</Body>
</Html>

我的代码有问题还是有不同的流程? html 文件与 TimeSet.class 文件位于同一文件夹中。当我运行小程序时,它工作正常

【问题讨论】:

  • 根本不要使用小程序。而是使用 Java Web Start 从链接启动框架。

标签: java html applet


【解决方案1】:

有两个入口点方法,init()start(),Java 将代表您的 Applet 调用它们。在您的情况下,请尝试在您的 Applet 中添加一个 init() 方法,然后它会调用您的 TimeSet() 方法:

public class TimeSet extends Applet{

    public void init () {
        TimeSet();
    }

    public void TimeSet(){
        //set the title
        frame = new JFrame();
        frame.setTitle("2 hour time set");

        //specify what happens when the close button is clicked
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //set main panel where all other panels will exist in
        mainPanel = new JPanel(new GridLayout(4,1));
        add(mainPanel);

        timePanel();
        ammountPanel();
        durationPanel();
        buttonSet();

        setVisible(true);
    }
}

顺便说一句,正如其他人可能会在这里评论的那样,Applet 是一种已弃用的技术,您不应该计划在发布产品中使用它。

【讨论】:

  • 它产生了一个错误,说 TimeSet() 是未定义的。是的,它是一个类,否则我永远不会使用它
  • 对不起,我省略了 TimeSet() 的返回类型(因为你也这样做了,我只是盲目地复制了你的代码)。现在再试一次。
  • html 中仍然没有出现任何内容
  • 您的小程序代码还有一个问题。我不是 Applet 方面的专家,我只是解决了您遇到的主要问题。
  • 尝试使用frame.show(),这样可能会出现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-11
  • 2018-03-22
  • 2021-09-05
  • 1970-01-01
相关资源
最近更新 更多