我在寫一個使用jButton的小應用程序。爲了這個問題,我們將其稱爲nextButton
。在整個程序生命週期中改變jButton的功能是否糟糕?有點像狀態機。改變jButtons的功能是不是很糟糕的設計?
所以說,每次點擊nextButton
我的應用程序的模式轉換到下一個「狀態」,並相應地改變視圖。
即
class NextButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
ServiceMode mode = model.getMode();
switch (mode) {
case SELECT:
// alter view and give nextButton function1
...
model.setMode(ServiceMode.CHECK);
break;
case CHECK:
// alter view and give nextButton function2
...
model.setMode(ServiceMode.COPY);
break;
case COPY:
// alter view and give nextButton function3
...
model.setMode(ServiceMode.END);
break;
case END:
// alter view and give nextButton function4
...
break;
}
}
}
是更好地只是實例每個都有自己的功能,新的按鈕?或者如果可能的話,使用一個具有多個功能的按鈕會更好嗎?
從來沒有聽說過它是一個糟糕的設計。創建按鈕來隱藏它們看起來不是一個更好的選擇。 – 2013-03-11 19:55:13
我通常看到一個按鈕與一個功能(設置)...否則你會在一大堆地方有類似的情況說明潛在..壞 – Randy 2013-03-11 19:55:36
我認爲這更多的UI設計問題。如果這樣的行爲是必需的你可以想出一個「好」的軟件設計。 – Chedy2149 2013-03-11 19:55:57