📄 filedialogdemo.java
字号:
//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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -