作者finch319 (Finch)
看板java
标题[问题] 请问关於一个JFileChooser的问题
时间Thu Mar 15 13:19:46 2007
因为程式需要读取一个档案
所以使用JFileChooser
原本使用没问题
但是後来不知道改到什麽地方
不管按JFileChooser里的"开启","取消"还是右上角的"X"
都会连原本的程式视窗一起关掉
以下是JFileChooser的程式码
public class ReadMdbListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
final JLabel statusbar = new JLabel("Output of your selection will go here");
int option = fc.showDialog(null, null);
if(option == JFileChooser.APPROVE_OPTION){
statusbar.setText("You Chose " + fc.getSelectedFile()!=null?
fc.getSelectedFile().getName():"nothing");
} else if(option == JFileChooser.CANCEL_OPTION){
statusbar.setText("You canceled.");
}
System.exit(0);
}
}
以下是程式建构子部分(主程式视窗)
public DriverGenerator(){
frame1 = new JFrame("驱动程式产生器 Driver Generator");
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
button1 = new JButton("读取资料库档案(*.mdb)");
button1.addActionListener(new ReadMdbListener());
button2 = new JButton("连线至资料库");
button2.addActionListener(new ConnectToDatabaseListener());
label1 = new JLabel("连线状态:");
label2 = new JLabel("选择System:");
chooseSystem = new JComboBox();
label3 = new JLabel("选择Class:");
chooseClass = new JComboBox();
button3 = new JButton("产生驱动程式");
button3.addActionListener(new GenerateDriverListener());
panel.add(button1);
panel.add(button2);
panel.add(label1);
panel.add(label2);
panel.add(chooseSystem);
panel.add(label3);
panel.add(chooseClass);
panel.add(button3);
frame1.getContentPane().add(BorderLayout.CENTER, panel);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(300, 225);
Dimension screen = frame1.getToolkit().getScreenSize();
Dimension window = frame1.getSize();
frame1.setLocation((int)(screen.getWidth() - window.getWidth())/2,
(int)(screen.getHeight() - window.getHeight())/2);
frame1.setVisible(true);
}
请教一下各位这样可能是我哪个地方出错了
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.70.94.234