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

📄 formmain.java

📁 呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜4444444444444444444
💻 JAVA
字号:
/**
 * 创建时间:2006年2月7日
 * 作    者:孙丰伟
 * 功	 能:主窗体,多文档窗口
 */
package cn.sunfengwei.employee.view;

import java.awt.*;
import java.awt.event.*;


import javax.swing.*;

import cn.sunfengwei.employee.model.*;

public class FormMain extends JFrame implements ActionListener{
  //保存背景颜色
    private ImageIcon background;

    //使用子窗体时,子窗体必须加载到主窗体的desktop中,使用时参考createFrame()方法
	private JDesktopPane desktop;
	private UserDTO account;
	public FormMain(String title){
		super(title);
		 int inset = 50;
        this.setBounds(inset,20,900,700);
		desktop=new JDesktopPane();
		this.setJMenuBar(this.createMenuBar());
		//将JDesktopPane对象加载到内容面板上
		this.setContentPane(desktop);
		this.addWindowListener(new WindowListener(){

			public void windowOpened(WindowEvent e) {
				// TODO 自动生成方法存根
				
			}
				//当单击窗口上关闭按钮时,询问系统操作人员,是否只的退出
			public void windowClosing(WindowEvent e) {
				// TODO 自动生成方法存根
				int i=JOptionPane.showConfirmDialog(FormMain.this,"你真的要退出系统吗?","系统询问",JOptionPane.YES_NO_OPTION);
				if(i==JOptionPane.YES_OPTION)
				{
					System.exit(0);
				}
				else
				{
					
					FormMain.this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);	
				}
			}

			public void windowClosed(WindowEvent e) {
				// TODO 自动生成方法存根
				
			}

			public void windowIconified(WindowEvent e) {
				// TODO 自动生成方法存根
				
			}

			public void windowDeiconified(WindowEvent e) {
				// TODO 自动生成方法存根
				
			}

			public void windowActivated(WindowEvent e) {
				// TODO 自动生成方法存根
				
			}

			public void windowDeactivated(WindowEvent e) {
				// TODO 自动生成方法存根
				
			}
			
		});
		//拖放窗体时的模式
		desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
		
		 background = new ImageIcon("back.jpg");//背景图片
	        JLabel label = new JLabel(background);//把背景图片显示在一个标签里面
	        //把标签的大小位置设置为图片刚好填充整个面板
	        label.setBounds(0,0,background.getIconWidth(),background.getIconHeight());
	        this.getLayeredPane().setLayout(null);
	        //把背景图片添加到分层窗格的最底层作为背景       
	       desktop.add(label,new Integer(Integer.MIN_VALUE));    
	      
	}
	 private JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        //系统菜单----------------------------------------------------
        JMenu menu = new JMenu("系统(S)");
        menu.setMnemonic(KeyEvent.VK_S);
        menuBar.add(menu);

        //Set up the first menu item.
        JMenuItem menuItem = new JMenuItem("用户管理(U)");
        menuItem.setMnemonic(KeyEvent.VK_U);
        menuItem.setActionCommand("user");
       menuItem.addActionListener(this);
        menu.add(menuItem);
        menu.addSeparator();
        menuItem=new JMenuItem("修改密码");
        menuItem.setActionCommand("password");
       menuItem.addActionListener(this);
        menu.add(menuItem);
        menu.addSeparator();
        //Set up the second menu item.
        menuItem = new JMenuItem("退出(Q)");
        menuItem.setMnemonic(KeyEvent.VK_Q);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_Q, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("quit");
      menuItem.addActionListener(this);
        menu.add(menuItem);
    //基本信息-----------------------------------------------------
        menu=new JMenu("基本信息(B)");
        menu.setMnemonic(KeyEvent.VK_B);
        menuItem=new JMenuItem("部门信息(D)");
        menuItem.setActionCommand("department");
        menuItem.setMnemonic(KeyEvent.VK_D);
         menuItem.addActionListener(this);
         menu.add(menuItem);
        menuBar.add(menu);
        //人事档案管理
        menu=new JMenu("人事档案管理(P)");
        menu.setMnemonic(KeyEvent.VK_P);
        menuItem=new JMenuItem("员工管理(E)");
        menuItem.setActionCommand("employee");
        menuItem.setMnemonic(KeyEvent.VK_E);
         menuItem.addActionListener(this);
         menu.add(menuItem);
        menuBar.add(menu);
        return menuBar;
    }
	 //每个子窗体加载到主窗体中时,先创建子窗体的对象,然后使用一个统一的方法加载
	   private void createFrame(JInternalFrame frame) {
	   	frame.setVisible(true); //necessary as of 1.3
        desktop.add(frame);
        try {
        	frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {}
    }
	   //菜单激活事件过程
	public void actionPerformed(ActionEvent e) {
		// 退出系统
		if(e.getActionCommand().equals("quit"))
		{
			System.exit(0);
		}
		//用户管理
		else if(e.getActionCommand().equals("user"))
		{
			
			FormUser userManager=new FormUser("用户管理");
			this.createFrame(userManager);
			
		}
		//修改当前用户密码
		else if(e.getActionCommand().equals("password"))
		{
			
			FormChangePassword changePassword=new FormChangePassword("修改密码");
			//将当前密码传到changePassword对象中
			changePassword.setUser(this.account);
			this.createFrame(changePassword);
		}
		//部门管理
		else if(e.getActionCommand().equals("department"))
		{
			FormDepartment framDepartment=new FormDepartment("部门信息");
			this.createFrame(framDepartment);
		}
		//员工基本信息管理
		else if(e.getActionCommand().equals("employee"))
		{
			FormEmployee framEmployee=new FormEmployee("员工信息");
			this.createFrame(framEmployee);
		}
	}
	
	public UserDTO getAccount() {
		return account;
	}
	public void setAccount(UserDTO account) {
		this.account = account;
	}
}

⌨️ 快捷键说明

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