?? resultlabelbean.java~8~
字號:
package calculatebean;import java.awt.*;import javax.swing.JLabel;import java.beans.*;/** * 這個Bean是用來獲取所選擇的運算符,并且返回它的值 */public class ResultLabelBean extends JLabel{ BorderLayout borderLayout1 = new BorderLayout(); private String opValue; /* 定義一個PropertyChangeSuppor實例對象,用于實現JavaBean的關聯屬性 */ private PropertyChangeSupport prochanges = new PropertyChangeSupport(this); public ResultLabelBean() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } private void jbInit() throws Exception { this.setLayout(borderLayout1); }// public void setOpValue(String opValue) public void setOpValue(String newopValue) { /* 實現屬性設置器的方法 */ /* 實現關聯屬性變化通知 */ String ChooseOpValue = "你還沒選者運算符!"; String oldOpValue = opValue; setText(opValue); /* 根據所按下的按鈕的值來判斷是那一種運算 */ if(newopValue.equals("+")) { ChooseOpValue = "你選擇的是加法運算。"; } if(newopValue.equals("-")) { ChooseOpValue = "你選擇的是減法運算。"; } if(newopValue.equals("*")) { ChooseOpValue = "你選擇的是乘法運算。"; } if(newopValue.equals("/")) { ChooseOpValue = "你選擇的是除法運算。"; } this.opValue = ChooseOpValue;// prochanges.firePropertyChange("opValue",oldOpValue,newOpValue); prochanges.firePropertyChange("opValue",oldOpValue,ChooseOpValue); } public String getOpValue() { /* 實現屬性獲取器的方法 */ return opValue; } public void addPropertyChangeListener(PropertyChangeListener l) { /* 注冊屬性監聽方法 */ prochanges.addPropertyChangeListener(l); } public void removePropertyChangeListener(PropertyChangeListener l) { /* 刪除屬性監聽方法 */ prochanges.removePropertyChangeListener(l); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -