首页 > 学院 > 开发设计 > 正文

Java 2中的MVC设计模式

2019-11-17 05:58:50
字体:
来源:转载
供稿:网友

一个好的用户界面(GUI)的设计通常可以在现实世界找到相应的表现。    

    例如,假如在您的面前摆放着一个类似于电脑键盘按键的一个简单的按钮,然而就是这么简单的一个按钮,我们就可以看出一个GUI设计的规则,它由两个主要的部分构成,一部分使得它具有了按钮应该具有的动作特性,例如可以被按下。另外一部分则负责它的表现,例如这个按钮是代表了A还是B。

//[C] 2002 Sun Microsystems, Inc.---
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class RunMVCPattern {
    public static void main(String [] arguments){
        System.out.PRintln("Example for the MVC pattern");
        System.out.println();
        System.out.println("In this example, a Contact is divided into");
        System.out.println(" Model, View and Controller components.");
        System.out.println();
        System.out.println("To illustrate the flexibility of MVC, the same");
        System.out.println(" Model will be used to provide information");
        System.out.println(" to two View components.");
        System.out.println();
        System.out.println("One view, ContactEditView, will provide a Contact");
        System.out.println(" editor window and will be paired with a controller");
        System.out.println(" called ContactEditController.");
        System.out.println();
        System.out.println("The other view, ContactDisplayView, will provide a");
        System.out.println(" display window which will reflect the changes made");
        System.out.println(" in the editor window. This view does not support");
        System.out.println(" user interaction, and so does not provide a controller.");
        System.out.println();
       
        System.out.println("Creating ContactModel");
        ContactModel model = new ContactModel();


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表