简体   繁体   English

MVC使用swing,如何让模型要求用户输入?

[英]MVC using swing, how to let the model ask for user input?

I have an MVC application where the Controller starts a Thread and therein starts a progressbar inside the View the action originated and calls the Model to go over a list of data selected in a View and process it in some way. 我有一个MVC应用程序,其中的Controller启动一个线程,然后在View内部启动一个进度条,该Action是由它发起的,并调用Model遍历View中选择的数据列表并以某种方式处理它。

Now while the Model is going over the data it encounters one or more entries that he wants the user to confirm for some reason. 现在,当模型遍历数据时,它会遇到一个或多个条目,出于某种原因,他希望用户确认该条目。 How should this be handled using MVC? 应该如何使用MVC处理呢?
Note that the Controller can handle multiple views, which of them should be responsible for the user input, how to differentiate between them, ... ? 请注意,Controller可以处理多个视图,其中哪个视图应负责用户输入,如何区分它们,...?

Validating input should be handled at the earliest opportunity possible in the view. 在视图中应尽早处理验证输入。 The view can query the model to verify an entry in context. 该视图可以查询模型以验证上下文中的条目。 As a concrete example , this InputVerifier overrides verify() to ensure numeric entry, but it might also ask the model do additional checks, perhaps comparing against other model attributes. 作为一个具体示例 ,此InputVerifier重写verify()以确保输入数字,但它也可能要求模型进行其他检查,也许与其他模型属性进行比较。 For example, 例如,

@Override
public boolean verify(JComponent input) {
    try {
        value = Double.parseDouble(field.getText());
        return model.isValid(value); // also check model
    } catch (NumberFormatException e) {
        return false;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM