⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filedialogdemo.java

📁 这是《Java 2 简明教程(第2版)》一书配套的源代码。
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

class dlg extends Frame 
    {
    Frame fe;
    Button bt1=new Button("Delete Main Frame"),
    bt2=new Button("Open File"),
    bt3=new Button("Save File");
    dlg(String str)
{
super(str);
add(bt1);
add(bt2);
add(bt3);
setLayout(new FlowLayout());
setSize(200,150);
setVisible(true);
addWindowListener(new koWindowListener());
bt1.addActionListener(new ko1ActionListener());
bt2.addActionListener(new ko1ActionListener());
bt3.addActionListener(new ko1ActionListener());
}
    class ko1ActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
   {
   fe=new Frame();
   if (e.getSource()==bt1)
      {
      dispose();
      System.exit(0);
      }
   if (e.getSource()==bt2)
      {
      FileDialog fd1=new FileDialog(fe,"Open File",FileDialog.LOAD);
      fd1.show();
      }
   if (e.getSource()==bt3)
      {
      FileDialog fd2=new FileDialog(fe,"Save File",FileDialog.SAVE);
      fd2.show();
      }
   }
}
    class koWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
     {
     dispose();
     System.exit(0);
    }
}
 }
public class FileDialogDemo 
   {
   public static void main(String args[])
{
Frame fe=new dlg("FileDialogDemo ");
fe.setBackground(Color.blue);
}
   }

⌨️ 快捷键说明

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