开始:Applet未初始化 [英] Start: Applet not initialized
本文介绍了开始:Applet未初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有任何错误,只有关于课堂的警告.它坚持不初始化,但我不知道出了什么问题.有人可以帮我吗?
I have no errors, only a warning on the class. It insists on not initializing though and I have no idea what''s wrong. Can someone please help me?
package com.saizen;
import java.applet.Applet;
import java.awt.Button;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class T3xt extends Applet implements ActionListener {
TextField text1;
Button button1, button2;
public void init(){
add(text1);
add(button1);
add(button2);
text1 = new TextField(20);
button1 = new Button("first");
button2 = new Button("second");
button1.addActionListener(this);
button2.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1){
text1.setText("Hello!");
}
if (e.getSource() == button2){
text1.setText("How are you today?");
}
}
}
推荐答案
只是交换顺序
just exchange sequence
add(text1);
text1 = new TextField(20);
button1 = new Button("first");
button2 = new Button("second");
add(text1);
add(button1);
add(button2);
text1 = new TextField(20);
button1 = new Button("first");
button2 = new Button("second");
让我知道会发生什么.
let me know what happen.
这篇关于开始:Applet未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文