filedialogdemo.java
来自「这是《Java 2 简明教程(第2版)》一书配套的源代码。」· Java 代码 · 共 64 行
JAVA
64 行
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 + =
减小字号Ctrl + -
显示快捷键?