java 中文件对话框的问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 14:21:18
import java.awt.*;
public class tt extends Frame
{static tt frm=new tt();
static FileDialog dia=new FileDialog(frm,"打开"); //这个一个 打 开文件的对话框,怎么样才能创建出保存文件的对话框?????
........
........

FileDialog dia=new FileDialog(frm,"打开",FileDialog.LOAD);
frm是这个文件对话框的宿主;“打开”是它的标题;
FileDialog dia2=new FileDialog(frm,"保存",FileDialog.SAVE);

用swing吧,awt没有swing好
showSaveDialog(null);
和jf1.showOpenDialog(null);

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class dfd extends JFrame implements ActionListener {
JFileChooser jf1 = new JFileChooser();
JFileChooser jf2 = new JFileChooser();
JButton jb1 = new JButton("open");
JButton jb2 = new JButton("save");

public dfd() {
jb1.addActionListener(this);
jb2.addActionListener(this);
GridLayout gl = new GridLayout();
setLayout(gl);
add(jb1);
add(jb2);
pack();
setVisible(true);