文件对话框的实例
packagelesson4;importjava.awt.*;importjava.awt.event.*;publicclassTestFileDialogexten...
package lesson4;
import java.awt.*;
import java.awt.event.*;
public class TestFileDialog extends Frame{
FileDialog filedg=new FileDialog(this);
Button bSave=new Button("Save");
Button bOpen=new Button("Open");
public TestFileDialog(){
init();
}
void init(){
this.setLayout(new FlowLayout());
this.add(bOpen);
this.add(bSave);
bOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
filedg.setMode(FileDialog.LOAD);
filedg.setTitle("打开");
filedg.setVisible(true);
System.out.println(filedg.getFile());
}
});
bSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
filedg.setMode(FileDialog.SAVE);
filedg.setTitle("保存");
filedg.setVisible(true);
}
});
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
e.getWindow().setVisible(false);
((Window)e.getComponent()).dispose();
System.exit(0);
}
});
this.setSize(500,300);
this.setTitle("FileDialog");
this.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestFileDialog();
}
} 展开
import java.awt.*;
import java.awt.event.*;
public class TestFileDialog extends Frame{
FileDialog filedg=new FileDialog(this);
Button bSave=new Button("Save");
Button bOpen=new Button("Open");
public TestFileDialog(){
init();
}
void init(){
this.setLayout(new FlowLayout());
this.add(bOpen);
this.add(bSave);
bOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
filedg.setMode(FileDialog.LOAD);
filedg.setTitle("打开");
filedg.setVisible(true);
System.out.println(filedg.getFile());
}
});
bSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
filedg.setMode(FileDialog.SAVE);
filedg.setTitle("保存");
filedg.setVisible(true);
}
});
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
e.getWindow().setVisible(false);
((Window)e.getComponent()).dispose();
System.exit(0);
}
});
this.setSize(500,300);
this.setTitle("FileDialog");
this.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestFileDialog();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询