?? filenamepathbean.java
字號:
package readfileprocessbarbean;import java.awt.*;import javax.swing.*;import javax.swing.JLabel;import java.beans.*;/** * 這是一個返回文件名和文件路徑的JavaBean */public class FileNamePathBean extends JLabel{ BorderLayout borderLayout1 = new BorderLayout(); private String fileNameAndPath; // 文件名和文件路徑 /* 實例化一個PropertyChangeSupport的局部對象 */ private PropertyChangeSupport changes = new PropertyChangeSupport(this); public FileNamePathBean() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } private void jbInit() throws Exception { this.setLayout(borderLayout1); } public void setFileNameAndPath() { /* 設計器的方法,其中引用關聯屬性 */ String oldfileNameAndPath = this.fileNameAndPath; // 定義一個變量,用以存放原來的屬性值 String newfileNameAndPath = null; // 定義一個變量,用以存放當前的屬性值 /* 調用showFileDialogWindows()方法來設置新的文件路徑和文件名 */ newfileNameAndPath = this.showFileDialogWindows(); this.fileNameAndPath = newfileNameAndPath; changes.firePropertyChange("fileNameAndPath",oldfileNameAndPath,newfileNameAndPath); } public String getFileNameAndPath() { /* 獲取單值屬性的值 */ return fileNameAndPath; } private String showFileDialogWindows() { /* 這是一個顯示文件瀏覽器的方法 */ String getTabSource = null; String returnStr = null; JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(null); getTabSource = jfc.getSelectedFile().toString(); if(getTabSource.length() > 1 && getTabSource != null) { returnStr = getTabSource.trim(); } else { returnStr = "unknown"; } return returnStr; } public void addPropertyChangeListener(PropertyChangeListener l) { /* 注冊屬性監聽方法 */ try {changes.addPropertyChangeListener(l);} catch(Exception e) {} } public void removePropertyChangeListener(PropertyChangeListener l) { /* 刪除屬性監聽方法 */ try {changes.removePropertyChangeListener(l);} catch(Exception e) {} }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -