打开文件对话框和保存文件对话框

作者在 2010-05-20 16:43:33 发布以下内容
package com.yds.gui.fourpart;

import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class FileSave implements ActionListener{
    Button b1,b2;
    FileDialog f_open,f_save;
    Frame f;
  public void Ui(){
      f=new Frame("打开文件和保存文件");
      b1=new Button("打开文件");
      b1.addActionListener(this);
      b2=new Button("保存文件");
      b2.addActionListener(this);
      f.add(b1,"North");
      f.add(b2);
      f.pack();
      f.setVisible(true);
      f_open=new FileDialog(f,"打开文件",FileDialog.LOAD);
      f_save=new FileDialog(f,"打开文件",FileDialog.SAVE);
  }
    public static void main(String[] args) {
        new FileSave().Ui();

    }
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==b1){
        f_open.setVisible(true);
    }
    else if(e.getSource()==b2){
        f_save.setVisible(true);
    }
        
    }

}
awt和Sring | 阅读 1107 次
文章评论,共0条
游客请输入验证码
浏览290889次