一个好的用户界面(GUI)的设计通常可以在现实世界找到相应的表现。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)例如,假如在您的面前摆放着一个类似于电脑键盘按键的一个简单的按钮,然而就是这么简单的一个按钮,我们就可以看出一个GUI设计的规则,它由两个主要的部分构成,一部分使得它具有了按钮应该具有的动作特性,例如可以被按下。另外一部分则负责它的表现,例如这个按钮是代表了A还是B。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/) //[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();