[問題] 請問一個JFileChooser的問題

看板java作者 (Finch)時間19年前 (2007/03/15 13:19), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
因為程式需要讀取一個檔案 所以使用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
文章代碼(AID): #15-DTpHQ (java)
文章代碼(AID): #15-DTpHQ (java)