[求助]要怎么改才能当点按钮时才会弹出对话框?
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);
}
}
请问要怎么改才能当自己点按钮的时候才会弹出对话框 ,修改以后请给我全部代码.多谢!!
搜索更多相关的解决方案:
对话框 按钮
----------------解决方案--------------------------------------------------------
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编辑过]
----------------解决方案--------------------------------------------------------
多谢myfor...请问你QQ多少啊??我加你..我还有很多JAVA问题请教!!!!我的是412222975
----------------解决方案--------------------------------------------------------