?? indexframe.java
字號:
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 + -