源程序如下:
import java.awt.*;
import java.awt.event.*;public class Test1 implements ActionListener {
Frame f;
Button b;
TextField tf; public void creat() {
f = new Frame("testing");
b = new Button("press");
b.addActionListener(this);
f.add(b,"North"); tf = new TextField();
f.add(tf,"South");
f.setSize(200,200);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
tf.setText("the Button is pressed"); // 这一句 点击Button没有打印
}
public static void main(String args[]) {
Test t = new Test();
t.creat();
}
}点击press按钮怎么没有显示哦"the Button is pressed"
import java.awt.*;
import java.awt.event.*;public class Test1 implements ActionListener {
Frame f;
Button b;
TextField tf; public void creat() {
f = new Frame("testing");
b = new Button("press");
b.addActionListener(this);
f.add(b,"North"); tf = new TextField();
f.add(tf,"South");
f.setSize(200,200);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
tf.setText("the Button is pressed"); // 这一句 点击Button没有打印
}
public static void main(String args[]) {
Test t = new Test();
t.creat();
}
}点击press按钮怎么没有显示哦"the Button is pressed"
解决方案 »
- 大家讨论一下ThreadLocal
- 怎么把Canvas的背景设置为透明
- 呵呵,我用到数据库了,但是安装的时候遇到了麻烦!
- 谁能帮我把这一小段java代码 改成javasript的(java逻辑运行正常)
- 怎么让drawLine()的极坐标变成contentPane的极坐标?
- 一个面试题,不知道怎么做
- IBE预定机票出现问题(急!!!!!!!!!!!!!)
- 英语考砸了! 专升本没戏了!就指望java 救命 了!! 请大家指路!
- 这段代码编译通过,可运行抛出异常!
- 一个关于内部类继承时候的初始化问题
- java程序问题??
- java类的功能太多,把功能分散给2个类,这个要怎么实现,或者用什么设设计模式?
运行结果符合预期,没有你说的问题。
你类名是Test1,却在main中这样写
Test t = new Test();
能有效果吗
Test t = new Test();
t.creat();
}改成:
public static void main(String args[]) {
Test1 t = new Test1 ();
t.creat();
}
Test t = new Test();你的类名是Test1,改一下就可以了。估计你没有用IDE。