⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmvcapp.java

📁 金旭亮的java教案
💻 JAVA
字号:
/*
 * @(#)MVC.java 1.0 03/02/09
 *
 * You can modify the template of this file in the
 * directory ..\JCreator\Templates\Template_1\Project_Name.java
 *
 * You can also create your own project template by making a new
 * folder in the directory ..\JCreator\Template\. Use the other
 * templates as examples.
 *
 * WmvcApp -Wmvc的主应用程序类
 *
 */


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public abstract class WmvcApp 
{
	private static WmvcApp theApp=null;
	//模型
	protected static WmvcModel theModel=null;
	//用户界面部分
	private static JFrame theFrame=null;
	private static JMenuBar theMenuBar=null;
	private static JToolBar theToolBar=null;
	private static JPanel theContentPanel=null;
	
	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 WmvcModel getModel(){return theModel;}
	public static void setModel(WmvcModel m) { theModel=m;}
	
	public static WmvcApp getApp()
	{
		return theApp;
	}
	//只有一个构造方法,可以扩充
	public WmvcApp(String aName,boolean cMenu,boolean cTool)
	{
		if(theApp!=null)
			return;
		theApp=this;
		initializeWmvc(aName,cMenu,cTool);
	}
	
	private void initializeWmvc(String aName,boolean cMenu,boolean cTool)
	{
		//第1步,建立主JFrame
		theFrame=new JFrame(aName);
		//处理关闭事件
		theFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		theFrame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				if(theApp.appClosing())
					System.exit(0);
			}
		});
		//第2步,菜单栏
		if(cMenu)
		{
			theMenuBar=new JMenuBar();
			theFrame.setJMenuBar(theMenuBar);
			
		}
		//第3步 JPanel
		theContentPanel=new JPanel();
		theContentPanel.setLayout(new BorderLayout());
		theContentPanel.setPreferredSize(new Dimension(400,300));
		
		//第4步 工具条
		if(cTool)
		{
			theToolBar=new JToolBar();
			theContentPanel.add(theToolBar,BorderLayout.NORTH);
		}
		//使用BorderLayout.SOUTH
		//把状态条(另一个ToolBar)加入到底部
		theFrame.setContentPane(theContentPanel);
	}
	
	public static void addMainPane(JComponent pane)
	{
		//这将"用户"窗格加入到内容窗格之中
		theContentPanel.add(pane);
	}
	
	public static void addMenu(JMenu menu)
	{
		if(theMenuBar==null)
			return ;
		theMenuBar.add(menu);
	}
	
	public static void showApp()
	{
		theFrame.pack();
		theFrame.setVisible(true);
	}
	
	public boolean appClosing()
	{
		return true; //缺省行为,自动关闭
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -