www.pudn.com > lxc.rar > WmvcApp.java


import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.event.*; 
 
public abstract class WmvcApp{ 
		private static WmvcApp theApp=null; 
		private static WmvcModel theModel=null; 
		 
		private static JFrame theFrame=null;//the top window 
		private static JPanel theContentPanel=null; 
		private static JMenuBar theMenuBar=null; 
		private static JToolBar theToolBar=null; 
		 
		public static JFrame getFrame(){ 
				return theFrame; 
			} 
		public static JPanel getContentPanel(){ 
				return theContentPanel; 
			} 
		public static JMenuBar getMenuBar(){ 
				return theMenuBar; 
			} 
		public static JToolBar getToolBar(){ 
				return theToolBar; 
			} 
		public static WmvcModel getModel(){ 
				return theModel; 
			} 
		public static void setModel(WmvcModel m){ 
				theModel=m; 
			} 
		public static WmvcApp getApp(){ 
				return theApp; 
			} 
			 
			 
		public WmvcApp(String name,boolean cMenu,boolean cTool){ 
				if(theApp!=null) 
					return; 
				initial(name,cMenu,cTool);	 
			} 
		private void initial(String name,boolean cMenu,boolean cTool){ 
				theFrame=new JFrame(name); 
				theFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
				theFrame.addWindowListener(new WindowAdapter(){ 
						public void windowClosing(WindowEvent e){ 
							if(theApp.appClosing()==true) 
								System.exit(0); 
						} 
					}); 
					 
				if(cMenu){ 
					theMenuBar=new JMenuBar(); 
					theFrame.setJMenuBar(theMenuBar); 
				} 
				 
				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 p){ 
				theContentPanel.add(p,BorderLayout.SOUTH); 
			} 
			 
			public static void addMenu(JMenu m){ 
				if(theMenuBar==null) 
					return; 
				theMenuBar.add(m);	 
			} 
			 
			public static void showApp(){ 
				theFrame.pack(); 
				theFrame.setVisible(true); 
			} 
			 
			public boolean appClosing(){ 
				return true; 
			} 
	}