我在写一个使用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