我尝试用Swing创建一个MVC应用程序。我对实施以及应该如何进行感到困惑。我的意思是:

  • 我有Gui,它是所有逻辑发送到名为controller的类的视图,并且我有一个具有模型属性的模型。(我读过MVC就是这样)
  • 我会根据需要输入多少个代码来创建一些随机代码,并将其与ActionListener一起传输到一个类命名控制器。在方法中使用控制器类上的按钮生成的随机代码。
    生成随机代码,然后我要将它们保存在数据库中。
    我很困惑如何将生成的代码保存在数据库中。
    我应该在类命名控制器中创建一个方法,以便从那里保存它们吗?还是另一个带有保存更新的类找到..........方法?如果是,那么为什么我要创建具有Model属性的Model类?以及如何使用Model类。
    如果我必须使用Model类,或者只需要拥有此类,那么剩下的就是了解如何使用Model类。如果Model类仅与属性一起存在,并且将其他地方保存起来,那么有什么用呢?
    通常使用哪种方法以便可以使用MVC模式?我感到困惑吗?任何帮助
    我忘了告诉我使用Hibernate。
    谢谢
    ps。我也读过这个http://java.sun.com/products/jfc/tsc/articles/architecture/,但我听不懂。
    public class code(){// this is the Model
        private int i;
        public void setter(int i){
            this.i=i;
        }
    
        public int getter(){
            return i;
        }
    
        public String generateStringInt() {
            return new BigInteger(190, random).toString(32);
        }
    
        // what ever i want to create with the int i variable i will do it on this class?
        ///then i will pass it on the controller to sent it on the view
        //OR save if i want to save it.?Is this way of thinking right?
        //Or is there any other way to do it ?
        /// if i have a Button and press it from the View it will generate this method?or
        // i have to do it else?
        public String generateStringInt() {
            return new BigInteger(190, random).toString(32);
        }
    
     }
    
     //then if i want to save i can just do it like
     //session.save(object) or is there any other way?
    

  • 现在好些了吗?
    谢谢

    最佳答案

    嗨,我在这里遇到了同样的问题,这是一个非常易于使用和理解所有内容的教程

    http://www.leepoint.net/notes-java/GUI/structure/ui-model-communication.html

    然后这个

    http://www.leepoint.net/notes-java/GUI/structure/30presentation-model.html这是我认为的最佳方法。

    10-07 13:04
    查看更多