所以我在 Java Swing 中有一个漂亮的、漂亮的 MVC 架构应用程序,现在我想添加一个进度条,我对将 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实现吗?