Swing 组件 黄色代码为什么没有实现

sunwxb 2009-10-10 09:35:00
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JButtonExample extends WindowAdapter implements ActionListener {
JFrame f;
JButton b;
JTextField tf;
int tag=0;

public static void main(String args[]) {
JButtonExample be=new JButtonExample();
be.go();
}
public void go(){
f=new JFrame("JButton Example");
b=new JButton("Sample");
b.addActionListener(this);
f.getContentPane().add(b,"South");

tf=new JTextField();
f.getContentPane().add(tf,"Center");
f.addWindowListener(this);
f.setSize(300,200);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
String s1="You have pressed the Button!";
String s2="You do another time!";

if(tag==0){
tf.setText(s1);
tag=1;
}else{
tf.setText(s2);
tag=0;
}

}
public void windowClosing(WindowEvent e) {
System.exit(0);
}


}
...全文
65 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
不善^ 2009-10-10
  • 打赏
  • 举报
回复
能关闭窗口了就说明实现了 使用了匿名类
sunwxb 2009-10-10
  • 打赏
  • 举报
回复
谢谢
swandragon 2009-10-10
  • 打赏
  • 举报
回复
没有实现是啥意思?
extends WindowAdapter
f.addWindowListener(this);
public void windowClosing(WindowEvent e) {
System.exit(0);
}


这不是实现了吗》?
java1109 2009-10-10
  • 打赏
  • 举报
回复
这是在关闭窗口时候起作用的
我测试了一下
没问题的
能够关掉窗口

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧