filedialogdemo.java

来自「java经典的源代码 我非常喜欢这个源代码 对于编程很有好处」· Java 代码 · 共 42 行

JAVA
42
字号
//dialog1.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FileDialogDemo extends JFrame
{
  private JPanel contentPane;
  private FlowLayout Layout1 = new FlowLayout();
  private Button button1 = new Button("显示文件对话框");
  private FileDialog d=new FileDialog(this,"打开文件");
  //Construct the frame
  public FileDialogDemo() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(Layout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("文件对话框");
    button1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        button1_actionPerformed(e);
      }
    });
    contentPane.add(button1);
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  void button1_actionPerformed(ActionEvent e) {
    d.show();
  }

  public static void main(String args[]){
    FileDialogDemo f=new FileDialogDemo();
    f.show();
  }
}

⌨️ 快捷键说明

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