当前位置: 技术问答>java相关
俺初学Java,有个问题请教,写了一段Java小程序(看里面),为什么没有运行结果:
来源: 互联网 发布时间:2015-02-08
本文导语: package buttontest; import java.awt.*; import java.applet.*; public class AppletButton extends Applet{ Button myButton1,myButton2; public void Init() { myButton1=new Button(); myButton1=new Button("Button2"); myButton1.setLabel("Button...
package buttontest;
import java.awt.*;
import java.applet.*;
public class AppletButton extends Applet{
Button myButton1,myButton2;
public void Init() {
myButton1=new Button();
myButton1=new Button("Button2");
myButton1.setLabel("Button1");
add(myButton1);
add(myButton2);
myButton2.setEnabled(false);
validate();
}
}
首先,我用JBuilder5新建个Applet,写完代码运行。显示:Applet已启动,但是,没有
其他效果呀?为什么呀?
import java.awt.*;
import java.applet.*;
public class AppletButton extends Applet{
Button myButton1,myButton2;
public void Init() {
myButton1=new Button();
myButton1=new Button("Button2");
myButton1.setLabel("Button1");
add(myButton1);
add(myButton2);
myButton2.setEnabled(false);
validate();
}
}
首先,我用JBuilder5新建个Applet,写完代码运行。显示:Applet已启动,但是,没有
其他效果呀?为什么呀?
|
public void Init()
改为
public void init()
大小写敏感!
改为
public void init()
大小写敏感!
|
import java.awt.*;
import java.applet.*;
public class AppletButton extends Applet{
Button myButton1,myButton2;
public void init() {
myButton1=new Button("Button1");
myButton2=new Button("Button2");
add(myButton1);
add(myButton2);
myButton2.setEnabled(false);
validate();
}
}
再试试!
import java.applet.*;
public class AppletButton extends Applet{
Button myButton1,myButton2;
public void init() {
myButton1=new Button("Button1");
myButton2=new Button("Button2");
add(myButton1);
add(myButton2);
myButton2.setEnabled(false);
validate();
}
}
再试试!
|
对的
init!
init!
|
jt80(冷酷无情) 的APPLET是可行的。我试过了。
你应该是想实现这样的功能吧。
myButton1=new Button();
+
myButton1=new Button();
=
myButton1=new Button("Button1");
?????
你应该是想实现这样的功能吧。
myButton1=new Button();
+
myButton1=new Button();
=
myButton1=new Button("Button1");
?????