作者H45 (!H45)
看板java
标题Re: [问题] java applet
时间Sun Feb 15 15:33:19 2009
※ 引述《s35300792001 (小朱)》之铭言:
: 最近看到java applet
: 以下程式码compile後出现错误
: 错误讯息是:
: class, interface, or enum expected
: 还有想请问要执行这种java applet是像以下这样吗?
: 开始→执行→cmd→到该档目录→appletviewer *.java
: 麻烦各位罗!
: ---------------------------------------------------------------
: import java.applet.Applet;
: import java.awt.*;
: import java.awt.event.*;
: /*
: < APPLET CODE=applet.class WIDTH=200 HEIGHT=200 >
: </APPLET>
: */
: public class applet extends Applet implements ActionListener
: {
: TextField text1;
: Button button1;
: public void init()
: {
: text1 = new TextField(20);
: add(text1);
: button1 = new Button("Click Here!");
: add(button1);
: button1.addActionListener(this);
: }
: }
: public void actionPerformed(ActionEvent event) //显示这行错误
: {
: String msg = new String("Hello from Java!");
: if ( event.getSource() == button1 ) //显示这行错误
: {
: text1.setText(msg);
: } //显示这行错误
: }
显然的错误:方法宣告必须放在类别括号内,如下型式
(○)
public class applet extends Applet implements ActionListener {
public void actionPerformed(ActionEvent event) {
// TODO your code
}
}
(╳)
public class applet extends Applet implements ActionListener {
}
public void actionPerformed(ActionEvent event) {
// TODO your code
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.247.13