我正在编写一个使用 jButton 的小型应用程序。为了这个问题,我们称它为nextButton
。在整个程序生命周期中更改 jButton 的功能是不好的设计吗?有点像状态机。
因此,每次单击nextButton
我的应用程序模式都会转换到下一个“状态”,并且视图会相应地改变。
IE
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;
}
}
}
只实例化具有自己功能的新按钮会更好吗?或者如果可能的话,使用一个具有多种功能的按钮会更好吗?