html 没有出现在 Applet 中
html not appearing for Applet
我尝试为我的小程序创建一个 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 文件位于同一文件夹中。当我 运行 小程序时,它工作正常
有两个入口点方法,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 是一种已弃用的技术,您不应计划在发布产品中使用它。
我尝试为我的小程序创建一个 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 文件位于同一文件夹中。当我 运行 小程序时,它工作正常
有两个入口点方法,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 是一种已弃用的技术,您不应计划在发布产品中使用它。