| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付赛孚耐:软件保护加密专家
身份认证令牌USB KEY   
共有 369 人关注过本帖
标题:为什么关闭按钮不起作用?
收藏  订阅  推荐  打印 
zzxwill
Rank: 3Rank: 3
等级:中级会员
帖子:398
积分:4130
注册:2007-8-15
为什么关闭按钮不起作用?

package applet;
import java.awt.*;
import java.awt.event.*;
//我添加了事件处理程序,但为什么关闭按钮还是不起作用?谢谢
public class MyTextArea extends Frame implements TextListener {
static Frame fr=new Frame("My new window!Superb!");
TextArea ta1,ta2;
public MyTextArea(){
setBounds(0,0,200,160);
String str1="Come on,boy!";
String str2="What a sunny day today!";
ta1=new TextArea(str1,10,6,TextArea.SCROLLBARS_VERTICAL_ONLY);
ta2=new TextArea(str2,10,6,TextArea.SCROLLBARS_HORIZONTAL_ONLY);
setLayout(new FlowLayout(FlowLayout.LEFT));
ta1.addTextListener(this);
ta2.setEditable(false);
add(ta1);
add(ta2);
setVisible(true);
}

public void textValueChanged(TextEvent e){
ta2.setText(ta1.getText());
}
public static void main(String args[]){
new MyTextArea();

fr.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);

}

}

搜索更多相关主题的帖子: ONLY  按钮  Frame  awt  
2007-11-18 15:13
csight
Rank: 3Rank: 3
等级:中级会员
威望:1
帖子:293
积分:3040
注册:2006-6-11

以下是引用zzxwill在2007-11-18 15:13:47的发言:

package applet;
import java.awt.*;
import java.awt.event.*;
//我添加了事件处理程序,但为什么关闭按钮还是不起作用?谢谢
public class MyTextArea extends Frame implements TextListener {
//static Frame fr=new Frame("My new window!Superb!");
TextArea ta1,ta2;
public MyTextArea(){
setBounds(0,0,200,160);
String str1="Come on,boy!";
String str2="What a sunny day today!";
ta1=new TextArea(str1,10,6,TextArea.SCROLLBARS_VERTICAL_ONLY);
ta2=new TextArea(str2,10,6,TextArea.SCROLLBARS_HORIZONTAL_ONLY);
setLayout(new FlowLayout(FlowLayout.LEFT));
ta1.addTextListener(this);
ta2.setEditable(false);
add(ta1);
add(ta2);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);

}
public void textValueChanged(TextEvent e){
ta2.setText(ta1.getText());
}
public static void main(String args[]){
new MyTextArea();

}

}


头可断,发型不可乱;血可流,皮鞋不可不擦油;
2007-11-18 17:07
Tony_bb
Rank: 1
等级:新手上路
帖子:37
积分:472
注册:2007-11-16

LS的意思是不能在构造器外面加监听么?我觉得应该可以吧~你看看这样改行不行,我在网吧没法测试
package applet;
import java.awt.*;
import java.awt.event.*;
//我添加了事件处理程序,但为什么关闭按钮还是不起作用?谢谢
public class MyTextArea extends Frame implements TextListener {
//static Frame fr=new Frame("My new window!Superb!");你这里创建的是一个普通的Frame而不是你的MyTextArea
TextArea ta1,ta2;
public MyTextArea(){
setBounds(0,0,200,160);
String str1="Come on,boy!";
String str2="What a sunny day today!";
ta1=new TextArea(str1,10,6,TextArea.SCROLLBARS_VERTICAL_ONLY);
ta2=new TextArea(str2,10,6,TextArea.SCROLLBARS_HORIZONTAL_ONLY);
setLayout(new FlowLayout(FlowLayout.LEFT));
ta1.addTextListener(this);
ta2.setEditable(false);
add(ta1);
add(ta2);
setVisible(true);
}

public void textValueChanged(TextEvent e){
ta2.setText(ta1.getText());
}
public static void main(String args[]){
new MyTextArea().addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);

;

}

2007-11-19 13:30
csight
Rank: 3Rank: 3
等级:中级会员
威望:1
帖子:293
积分:3040
注册:2006-6-11

"LS的意思是不能在构造器外面加监听么?"
我没说不能在外面添加;反正有添加就行,在哪里无所谓;

头可断,发型不可乱;血可流,皮鞋不可不擦油;
2007-11-19 14:23
千里冰封
Rank: 12Rank: 12Rank: 12
来自:灌水之王
等级:版主
威望:155
帖子:28360
积分:4616
注册:2006-2-26

还有一点,不要再用AWT了,尽量用SWING里面的组件吧

可惜不是你,陪我到最后
2007-11-20 13:35
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.067008 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved