所以我在
Java Swing中有这个漂亮的漂亮的MVC架构应用程序,现在我想添加一个进度条,我对Good Design Methods感到困惑,将JProgressBar合并到我的视图中.我是不是该:
>将DefaultBoundedRangeModel添加到我的控制器状态,然后导出它?
class Model {
final private DefaultBoundedRangeModel progress
= new DefaultBoundedRangeModel();
public void getProgressModel() { return progress; }
public void setProgressCount(int i) { progress.setValue(i); }
}
class Controller {
Model model;
int progressCount;
void doSomething()
{
model.setProgressCount(++progressCount);
}
}
class View {
void setup(Model m)
{
JProgressBar progressBar = /* get or create progress bar */ ;
progressBar.setModel(m.getProgressModel());
}
}
/* dilemma: Model allows progress to be exported so technically
all of the progress state could be set by someone else; should it be put
into a read-only wrapper? */
>使用JGoodies Binding尝试将JProgressBar的视觉状态连接到我的模型状态?
class Model {
private int progress;
public void getProgressCount() { return progress; }
public void setProgressCount(int i) { progress = i; }
}
class View {
void setup(Model m)
{
ProgressBar progressBar = /* get or create progress bar */ ;
CallSomeMagicMethodToConnect(m, "progressCount", progressBar, "value");
// is there something that works like the above?
// how do I get it to automatically update???
}
}
>或其他什么?
编辑:更具体地说:有人能指出我的Java应用程序的现实源的一个很好的例子,它有一个包含进度条的状态栏,并且有一个像样的MVC实现吗?