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

📄 indexframe.java

📁 java swing 开发的一些实例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.mwq.frame;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import com.mwq.PersonnelManage;
import com.mwq.frame.personnel.BringUpSelectedPanel;
import com.mwq.frame.personnel.RecordSelectedPanel;
import com.mwq.frame.personnel.RewardsAndPunishmentPanel;
import com.mwq.frame.personnel.TimecardPanel;
import com.mwq.frame.system.DataPanel;
import com.mwq.frame.system.FrameworkPanel;
import com.mwq.frame.treatement.CriterionSetPanel;
import com.mwq.frame.treatement.PersonnelSetPanel;
import com.mwq.frame.treatement.ReportFormsPanel;
import com.mwq.frame.user.AddUserPanel;
import com.mwq.frame.user.UpdatePasswordDialog;
import com.mwq.hibernate.Dao;
import com.mwq.hibernate.mapping.TbRecord;

public class IndexFrame extends JFrame {

	private JTree tree;

	final JPanel rightPanel = new JPanel();

	private TbRecord record;

	private final Dao dao = Dao.getInstance();

	/**
	 * Launch the application
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			IndexFrame frame = new IndexFrame(null);
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	public IndexFrame(TbRecord tbRecord) {
		super();

		this.record = tbRecord;

		setResizable(false);
		setExtendedState(IndexFrame.MAXIMIZED_BOTH);// 设置窗口以最大化打开
		setTitle(" T 科技");
		setBounds(0, 0, 950, 700);
		setBounds(0, 0, 1024, 768);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JPanel topPanel = new JPanel();
		topPanel.setLayout(new BorderLayout());
		topPanel.setPreferredSize(new Dimension(0, 100));
		getContentPane().add(topPanel, BorderLayout.NORTH);

		final JLabel label = new JLabel();
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setHorizontalTextPosition(SwingConstants.CENTER);
		URL resource = IndexFrame.this.getClass().getResource("/img/logo.JPG");
		ImageIcon icon = new ImageIcon(resource);
		label.setIcon(icon);
		label.setBorder(new TitledBorder(null, "",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null));
		label.setPreferredSize(new Dimension(160, 0));
		topPanel.add(label, BorderLayout.WEST);

		final JPanel buttonPanel = new JPanel();// 创建工具栏面板
		final GridLayout gridLayout = new GridLayout(1, 0);// 创建一个水平箱式布局管理器对象
		gridLayout.setVgap(6);// 箱的垂直间隔为6像素
		gridLayout.setHgap(6);// 箱的水平间隔为6像素
		buttonPanel.setLayout(gridLayout);// 设置工具栏面板采用的布局管理器为箱式布局
		buttonPanel.setBackground(new Color(90, 130, 189));// 设置工具栏面板的背景色
		buttonPanel.setBorder(new TitledBorder(null, "",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null));// 设置工具栏面板采用的边框样式
		topPanel.add(buttonPanel, BorderLayout.CENTER);// 将工具栏面板添加到上级面板中

		final JButton recordShortcutKeyButton = new JButton();// 创建进入“档案管理”的快捷按钮
		resource = this.getClass().getResource("/img/record.JPG");
		icon = new ImageIcon(resource);
		recordShortcutKeyButton.setIcon(icon);
		// 为按钮添加事件监听器,用来捕获按钮被点击的事件
		recordShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rightPanel.removeAll();// 移除内容面板中的所有内容
				rightPanel.add(new RecordSelectedPanel(rightPanel),
						BorderLayout.CENTER);// 将档案管理面版添加到内容面板中
				SwingUtilities.updateComponentTreeUI(rightPanel);// 刷新内容面板中的内容
			}
		});
		buttonPanel.add(recordShortcutKeyButton);

		final JButton timecardShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/timecard.JPG");
		icon = new ImageIcon(resource);
		timecardShortcutKeyButton.setIcon(icon);
		timecardShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rightPanel.removeAll();
				rightPanel.add(new TimecardPanel(), BorderLayout.CENTER);
				SwingUtilities.updateComponentTreeUI(rightPanel);
			}
		});
		buttonPanel.add(timecardShortcutKeyButton);

		final JButton rewardsAndPunishmentShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/rewAndPun.JPG");
		icon = new ImageIcon(resource);
		rewardsAndPunishmentShortcutKeyButton.setIcon(icon);
		rewardsAndPunishmentShortcutKeyButton
				.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						rightPanel.removeAll();
						rightPanel.add(new RewardsAndPunishmentPanel(),
								BorderLayout.CENTER);
						SwingUtilities.updateComponentTreeUI(rightPanel);
					}
				});
		buttonPanel.add(rewardsAndPunishmentShortcutKeyButton);

		final JButton reportFormsShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/stat.JPG");
		icon = new ImageIcon(resource);
		reportFormsShortcutKeyButton.setIcon(icon);
		reportFormsShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rightPanel.removeAll();
				rightPanel.add(new ReportFormsPanel(), BorderLayout.CENTER);
				SwingUtilities.updateComponentTreeUI(rightPanel);
			}
		});
		buttonPanel.add(reportFormsShortcutKeyButton);

		final JButton basicDataShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/data.JPG");
		icon = new ImageIcon(resource);
		basicDataShortcutKeyButton.setIcon(icon);
		basicDataShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rightPanel.removeAll();
				rightPanel.add(new DataPanel(), BorderLayout.CENTER);
				SwingUtilities.updateComponentTreeUI(rightPanel);
			}
		});
		buttonPanel.add(basicDataShortcutKeyButton);

		final JButton updatePasswordShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/password.JPG");
		icon = new ImageIcon(resource);
		updatePasswordShortcutKeyButton.setIcon(icon);
		if (record == null)// 当record为null时,说明是通过默认用户登录的,此时不能修改密码
			updatePasswordShortcutKeyButton.setEnabled(false);// 在这种情况下设置按钮不可用
		updatePasswordShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rightPanel.removeAll();
				SwingUtilities.updateComponentTreeUI(rightPanel);
				UpdatePasswordDialog dialog = new UpdatePasswordDialog();// 创建用来修改密码的对话框
				dialog.setRecord(record);// 将当前登录管理员的档案对象传入对话框
				dialog.setVisible(true);// 设置对话框为可见的,即显示对话框
			}
		});
		buttonPanel.add(updatePasswordShortcutKeyButton);

		final JButton counterShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/calculator.JPG");
		icon = new ImageIcon(resource);
		counterShortcutKeyButton.setIcon(icon);
		counterShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Desktop desktop = Desktop.getDesktop();// 获得当前系统对象
				File file = new File("C:/WINDOWS/system32/calc.exe");// 创建一个系统计算器对象
				try {
					desktop.open(file);// 打开系统计算器
				} catch (Exception e1) {// 当打开失败时,弹出提示信息
					JOptionPane.showMessageDialog(null, "很抱歉,未能打开系统自带的计算器!",
							"友情提示", JOptionPane.INFORMATION_MESSAGE);
					return;
				}
			}
		});
		buttonPanel.add(counterShortcutKeyButton);

		final JButton excelShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/excel.JPG");
		icon = new ImageIcon(resource);
		excelShortcutKeyButton.setIcon(icon);
		excelShortcutKeyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Desktop desktop = Desktop.getDesktop();
				File file = new File("res/other/new.xls");
				try {
					desktop.open(file);
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(null, "很抱歉,您的机器还没有安装Office!",
							"友情提示", JOptionPane.INFORMATION_MESSAGE);
					return;
				}
			}
		});
		buttonPanel.add(excelShortcutKeyButton);

		final JButton exitShortcutKeyButton = new JButton();
		resource = this.getClass().getResource("/img/exit.JPG");

⌨️ 快捷键说明

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