根据需要吧,看看mvc的模式好了

解决方案 »

  1.   

    UI类可以采用单例模式,
    UI类里面可以包括:
    一个私有的构造函数,这样可以控制外界无法对UI类实例化
    一个私有的静态的UI对象,UI的对象可以自己实例化,这样便于管理
    一个静态的工厂方法(public static),将那个UI对象提供给外界使用。action类只要有一个UI类的接口成员就可以了这样你修改UI类就不会影响ACTION类
    而且别的类都可以使用UI类,
    实现了OPEN-CLOSE原则
      

  2.   

    不明白maddingxu(蓝牙剑客)的内容,可否有实际代码?
      

  3.   

    /*
     * JmvcApp
     * Created on 2005-2-11
     * Version 1.1
     * Copyright (c) 2005, Jeffrey Xu
     */
    package com.jeffreyxu.frame;import java.awt.*;
    import javax.swing.*;/**
     * @author Jeffrey Xu
     * @version 1.1
     * Jmvc 的主应用程序类
     */
    public abstract class JmvcApp {

    private static JmvcApp theApp = null;     // Singleton

    //模型
    protected static JmvcModel theModel = null;

    //GUI界面部分
    private static JFrame theFrame = null;    // 顶层窗体
    private static JMenuBar theMenuBar = null;
    private static JToolBar theToolBar = null;
    private static JPanel theContentPanel = null;

    public JmvcApp(String aName, boolean cMenu, boolean cTool) {
    if (theApp != null)
    return;
    theApp = this;
    initializeJmvc(aName, cMenu, cTool);
    }

    private void initializeJmvc(String aName, boolean cMenu, boolean cTool) {
    // 建立主JFrame
    theFrame = new JFrame(aName);

    theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 建立菜单栏
    if (cMenu) {
    theMenuBar = new JMenuBar();
    theFrame.setJMenuBar(theMenuBar);
    }

    // JPanel
    theContentPanel = new JPanel();
    theContentPanel.setLayout(new BorderLayout());
            theContentPanel.setPreferredSize(new Dimension(400, 300));
            
            if (cTool) {
             theToolBar = new JToolBar();
             theContentPanel.add(theToolBar, BorderLayout.NORTH);
            }
            
            theFrame.setContentPane(theContentPanel);
    }

    public static void addMainPane(JComponent pane) {

    }

    public static void addMenu(JMenu menu) {
    if (theMenuBar == null)
    return;
    theMenuBar.add(menu);
    }

    public static JFrame getFrame() {
    return theFrame;
    }

    public static JMenuBar getMenuBar() {
    return theMenuBar;
    }

    public static JToolBar getToolBar() {
    return theToolBar;
    }

    public static JPanel getContentPanel() {
    return theContentPanel;
    }

    public static JmvcModel getModel() {
    return theModel;
    }

    public static void setModel(JmvcModel m) {
    theModel = m;
    }

    public static JmvcApp getApp() {
    return theApp;
    }

    public static void showApp() {
    theFrame.pack();
    theFrame.setVisible(true);
    }

    public boolean appClosing() {
    return true;
    }

    }
      

  4.   

    /*
     * JmvcView.java
     * 
     * Created on 2005-2-13
     * Version 1.1
     * Copyright (c) 2005, Jeffrey Xu
     */
    package com.jeffreyxu.frame;import java.util.*;/**
     * @author Jeffrey Xu
     * @version 1.1
     */public class JmvcView implements Observer {
        public void update(Observable observed, Object value) {
            updateView();
        }    public void updateView() {    }
    }
      

  5.   

    /*
     * JmvcModel
     * Created on 2005-2-13
     * Version 1.1
     * Copyright (c) 2005, Jeffrey Xu
     */
    package com.jeffreyxu.frame;import java.util.*;/**
     * @author Jeffrey Xu
     * @version 1.1
     * Jmvc Model 基类
     */public class JmvcModel extends Observable {
        
        public JmvcModel() {
            super();
        }
        
        public void addView(JmvcView view) {
            addObserver((Observer) view);
        }
        
        public void deleteView(JmvcView view) {
            deleteObserver((Observer) view);
        }
        
        public void notifyViews() {
            setChanged();
            notifyObservers();
        }
    }