學(xué)生作品_文件對(duì)話框說明_第1頁
學(xué)生作品_文件對(duì)話框說明_第2頁
學(xué)生作品_文件對(duì)話框說明_第3頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、一、作品要求編寫文件框小程序。二、學(xué)生作品分析1、代碼分析代碼分析如下:public class FileChooserDemo extends JPanelimplement sic private final String newline = n; JButton openButton, saveButton; JTextArea log;JFileChooser fc;public FileChooserDemo() super(new BorderLayout(); log = new JTextArea(15,40);ionListener log.setMargin(new Ins

2、ets(10,10,10,10); log.setEditable(false);JScrollPane logScrollPane = new JScrollPane(log);/創(chuàng)建一個(gè)文件過濾,使用當(dāng)前目錄 fc = new JFileChooser(.);/過濾條件在 MyFilter 類中定義 fc.addChoosableFileFilter(new MyFilter(); openButton = new JButton(打開文件,createImageIcon(images/Open16.gif); openButton.addActionListener(this);save

3、Button = new JButton(保存文件,createImageIcon(images/Save16.gif); saveButton.addActionListener(this);/構(gòu)建一個(gè)面板,添加“打開文件”和“保存文件” JPanel buttonPanel = new JPanel(); buttonPanel.add(openButton); buttonPanel.add(saveButton);add(buttonPanel, BorderLayout.PAGE_START);add(logScrollPane, BorderLayoENTER);/*方法說明:事件

4、處理*輸入?yún)?shù):*返回類型:*/public void actionPerformed(ActionEvent e) /當(dāng)點(diǎn)擊“打開文件”按鈕if (e.getSource() = openButton) returnVal = fc.showOpenDialog(FileChooserDemo.this); if (returnVal = JFileChooser.APPROVE_OPTION) File file = fc.getSelectedFile();/在這里添加一些對(duì)文件的處理log.append(打開文件: + file.getName() + newline); else l

5、og.append(打開文件被用戶取消! + newline);/點(diǎn)擊“保存文件”按鈕 else if (e.getSource() = saveButton) returnVal = fc.showSaveDialog(FileChooserDemo.this); if (returnVal = JFileChooser.APPROVE_OPTION) File file = fc.getSelectedFile();/在這里添加一些對(duì)文件的處理log.append(保存文件: + file.getName()+ newline); else log.append(保存文件被用戶取消! +

6、newline);/*方法說明:獲取圖像對(duì)象*輸入?yún)?shù):String path*返回類型:ImageIcon*/路徑對(duì)象protected sic ImageIcon createImageIcon(String path) .URL imgURL = FileChooserDemo.class.getResource(path); if (imgURL != null) return new ImageIcon(imgURL); else System.err.prln(Couldnt find file: + path); return null;public sic void main(

7、String args) JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true);/創(chuàng)建窗體JFrame frame = new JFrame(FileChooserDemo); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/創(chuàng)建一個(gè)面板JComponent newContentPane = new FileChooserDemo();newContentPatOpaque(true);frame.setContentPane(newContentPane);/顯示窗體frame.pack(); frame.setVisible(true);三、作品操作說明界面四、作品參與學(xué)生信息班級(jí)學(xué)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論