标题:[求助]要怎么改才能当点按钮时才会弹出对话框?
只看楼主
meizhelan
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-6-6
 问题点数:0 回复次数:2 
[求助]要怎么改才能当点按钮时才会弹出对话框?



import java.awt.*;
import java.awt.event.*;

public class Myproject extends Frame implements ActionListener {
public static void main(String args[]) {

TextArea ta;
Button button;

Frame fr = new Frame("KOF");
ta = new TextArea();
fr.add(ta,BorderLayout.CENTER);
button = new Button("读取");
fr.add(button,BorderLayout.SOUTH);
//button.addActionListene(this);
fr.setSize(200,100);
fr.setVisible(true);
FileDialog dialog = new FileDialog(fr,"My FileDialog");
dialog.setVisible(true);
String fname = dialog.getDirectory() + dialog.getFile();
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}

public void actionPerformed(ActionEvent event) {
Object dialog = null;
if(dialog == null) {
dialog = new FileDialog(this,"My FileDialog");
}
((Component) dialog).setVisible(true);
}

public Myproject(String str) {
super(str);
}
}
请问要怎么改才能当自己点按钮的时候才会弹出对话框 ,修改以后请给我全部代码.多谢!!

搜索更多相关主题的帖子: 对话框 按钮 
2006-06-11 20:05
myfor
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:357
专家分:6
注 册:2006-3-13
得分:0 

import java.awt.*;
import java.awt.event.*;

public class Myproject extends Frame implements ActionListener {

public static void main(String args[]) {
new Myproject();
}
private FileDialog dialog;
private Button button;
private TextArea ta;
Myproject(){

Frame fr = new Frame("KOF");
ta = new TextArea();
fr.add(ta,BorderLayout.CENTER);
button = new Button("读取");
fr.add(button,BorderLayout.SOUTH);
button.addActionListener(this);
fr.setSize(200,100);
fr.setVisible(true);
dialog = new FileDialog(fr,"My FileDialog");
dialog.setVisible(false);
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}

public void actionPerformed(ActionEvent event) {

if(event.getSource()==button){
dialog.setVisible(true);
String fname = dialog.getDirectory() + dialog.getFile();
ta.setText(fname);
}
}
}

[此贴子已经被作者于2006-6-11 22:08:11编辑过]


广告位招租
2006-06-11 21:55
meizhelan
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-6-6
得分:0 
多谢myfor...请问你QQ多少啊??我加你..我还有很多JAVA问题请教!!!!我的是412222975
2006-06-11 22:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-71488-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.253882 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved