一個(gè)好的用戶界面(GUI)的設(shè)計(jì)通常可以在現(xiàn)實(shí)世界找到相應(yīng)的表現(xiàn)。
例如,假如在您的面前擺放著一個(gè)類似于電腦鍵盤按鍵的一個(gè)簡(jiǎn)單的按鈕,然而就是這么簡(jiǎn)單的一個(gè)按鈕,我們就可以看出一個(gè)GUI設(shè)計(jì)的規(guī)則,它由兩個(gè)主要的部分構(gòu)成,一部分使得它具有了按鈕應(yīng)該具有的動(dòng)作特性,例如可以被按下。另外一部分則負(fù)責(zé)它的表現(xiàn),例如這個(gè)按鈕是代表了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. 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();
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注