afiledialog.java

来自「java学习材料」· Java 代码 · 共 55 行

JAVA
55
字号
//源文件名:aFileDialog.java
//在下载源程序中的文件夹:1001文件对话框\方法1
import java.awt.*;
import java.awt.event.*;
public class aFileDialog
{
    public static void main(String args[])
    {
        frame1 fwin=new frame1("文件对话框示例");
    }
}

class frame1 extends Frame implements ActionListener
{
    FileDialog saveDialog,openDialog;
    Button btn1,btn2;
    frame1(String tit)
    {
        super(tit);
        setLayout(new FlowLayout());
        setSize(300,100);
        setLocation(350,200);
        setVisible(true);
        btn1=new Button("   打开   ");
        btn2=new Button("  另存为  ");
        add(btn1);
        add(btn2);
        pack();
        saveDialog=new FileDialog(this,"另存为",FileDialog.SAVE);
        openDialog=new FileDialog(this,"打开",FileDialog.LOAD);
        btn1.addActionListener(this);
        btn2.addActionListener(this);
        WindowAdapter w= new WindowAdapter1();
        addWindowListener(w);
    }

    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==btn1)
        {
            openDialog.setVisible(true);
        }
        if(e.getSource()==btn2)
        {
            saveDialog.setVisible(true);
        }
    }
}
class WindowAdapter1 extends WindowAdapter
{
    public void windowClosing(WindowEvent e)
    {
        System.exit(0);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?