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

📄 mainframe.java

📁 完成界面功能
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package edu.sdu;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.JXMonthView;
import org.jvnet.substance.SubstanceDefaultLookAndFeel;

public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JMenuBar topJMenuBar = null;

	private JMenu loginMenu = null;

	private JMenu helpMenu = null;

	private JMenuItem loginMenuItem = null;

	private JMenuItem logoutMenuItem = null;

	private JMenuItem exitMenuItem = null;

	private JMenuItem helpMenuItem = null;

	private JMenuItem aboutMenuItem = null;

	private JPanel statusPanel = null;

	private JLabel statusLabel = null;

	private JScrollPane mainScrollPane = null;

	private JTable userTable = null;

	private JPanel userPanel = null;

	private JTabbedPane mainTabbedPane = null;

	private JPanel searchPanel = null;

	private JLabel jLabel = null;

	private JTextField searchTextField = null;

	private JButton searchButton = null;

	private JPanel userInfoPanel = null;

	private JPanel bookPanel1 = null;

	private JPanel jPanel1 = null;

	private JPanel inputPanel = null;

	private JPanel btnPanel = null;

	private JButton updateButton = null;

	private JLabel usernameLabel = null;

	private JLabel passwoedLabel = null;

	private JPasswordField PasswordField = null;

	private JLabel genderLabel = null;

	private JLabel birthLabel = null;

	private JXDatePicker birthTextField = null;

	private JLabel addressLabel = null;

	private JTextField addressTextField = null;

	private JLabel user_descLabel = null;

	private JTextField user_descTextField = null;

	private JLabel msgLabel = null;

	private JPanel genderjPanel = null;

	private JRadioButton maleRadioButton = null;

	private JRadioButton femaleRadioButton = null;

	private static User user = null;

	private JTextField usernameTextField = null;

	private JPopupMenu rightPopupMenu = null;

	private JMenuItem addMenuItem = null;

	private JMenuItem updateMenuItem = null;

	private JMenuItem deleteMenuItem = null;

	private JButton addButton = null;

	private JButton deleteButton = null;

	private static boolean isSelect = false;

	private JScrollPane bookmainScrollPane = null;

	private JTable bookTable = null;

	private JPanel booksearchPanel = null;

	private JPanel bookInfoPanel = null;

	private JLabel searchLabel1 = null;

	private JTextField searchbookTextField = null;

	private JButton booksearchButton = null;

	private JPanel bookinputPanel = null;

	private JPanel bookbtnPanel = null;

	private JLabel booknameLabel1 = null;

	private JTextField booknameTextField = null;

	private JLabel publishdateLabel1 = null;

	private JXDatePicker publishdateField = null;

	private JButton jButton = null;

	private JButton addButton1 = null;

	private JButton updateButton1 = null;

	private JButton deleteButton1 = null;

	/**
	 * This method initializes topJMenuBar
	 * 
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getTopJMenuBar() {
		if (topJMenuBar == null) {
			topJMenuBar = new JMenuBar();
			topJMenuBar.add(getLoginMenu());
			topJMenuBar.add(getHelpMenu());
		}
		return topJMenuBar;
	}

	/**
	 * This method initializes loginMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getLoginMenu() {
		if (loginMenu == null) {
			loginMenu = new JMenu();
			loginMenu.setText("登录");
			loginMenu.add(getLoginMenuItem());
			loginMenu.add(getLogoutMenuItem());
			loginMenu.add(getExitMenuItem());
		}
		return loginMenu;
	}

	/**
	 * This method initializes helpMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getHelpMenu() {
		if (helpMenu == null) {
			helpMenu = new JMenu();
			helpMenu.setText("帮助");
			helpMenu.add(getHelpMenuItem());
			helpMenu.add(getAboutMenuItem());
		}
		return helpMenu;
	}

	/**
	 * This method initializes loginMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getLoginMenuItem() {
		if (loginMenuItem == null) {
			loginMenuItem = new JMenuItem();
			loginMenuItem.setText("登录(Login)");
			loginMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
					KeyEvent.CTRL_MASK));
			loginMenuItem.setMnemonic('L');
			loginMenuItem
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
//							new LoginDialog().setVisible(true);
							String username = JOptionPane.showInputDialog("请输入用户名:");
							if(username == null){
								return;
							}
							
							String password = JOptionPane.showInputDialog("请输入用户的密码:");
							if(password == null){
								return;
							}
							
							if(UserDao.userQuery(username, password)){
								jContentPane.setVisible(true);
							}
							else{
								JOptionPane.showMessageDialog(null,"登录失败,返回");
								new MainFrame().setVisible(true);
							}
						}
					});
		}
		return loginMenuItem;
	}

	/**
	 * This method initializes logoutMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getLogoutMenuItem() {
		if (logoutMenuItem == null) {
			logoutMenuItem = new JMenuItem();
			logoutMenuItem.setText("注销(Logout)");
			logoutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
					KeyEvent.ALT_MASK));
			logoutMenuItem.setMnemonic('L');
			logoutMenuItem
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							dispose();
							new MainFrame().setVisible(true);
						}
					});

		}
		return logoutMenuItem;
	}

	/**
	 * This method initializes exitMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem();
			exitMenuItem.setText("退出(exit)");
			exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
					KeyEvent.CTRL_MASK));
			exitMenuItem.setMnemonic('e');
			exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return exitMenuItem;
	}

	/**
	 * This method initializes helpMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getHelpMenuItem() {
		if (helpMenuItem == null) {
			helpMenuItem = new JMenuItem();
			helpMenuItem.setText("帮助(help)");
			helpMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
					KeyEvent.CTRL_MASK));
			helpMenuItem.setMnemonic('h');
			helpMenuItem.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					HelpDialog help = new HelpDialog(MainFrame.this);
					help.setVisible(true);
				}
			});
		}
		return helpMenuItem;
	}

	/**
	 * This method initializes aboutMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getAboutMenuItem() {
		if (aboutMenuItem == null) {
			aboutMenuItem = new JMenuItem();
			aboutMenuItem.setText("关于(about)");
			aboutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0,
					KeyEvent.CTRL_MASK));
			aboutMenuItem.setMnemonic('a');
			aboutMenuItem
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							AboutDialog about = new AboutDialog(MainFrame.this);
							about.setVisible(true);
						}
					});
		}
		return aboutMenuItem;
	}

	/**
	 * This method initializes statusPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getStatusPanel() {
		if (statusPanel == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setAlignment(FlowLayout.LEFT);
			statusLabel = new JLabel();
			statusLabel.setText("已登录");
			statusPanel = new JPanel();
			statusPanel.setLayout(flowLayout);
			statusPanel.add(statusLabel, null);
		}
		return statusPanel;
	}

	/**
	 * This method initializes mainScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getMainScrollPane() {
		if (mainScrollPane == null) {
			mainScrollPane = new JScrollPane();
			mainScrollPane.setBorder(null);
			mainScrollPane.setViewportView(getUserTable());
		}
		return mainScrollPane;
	}

	/**
	 * This method initializes userTable
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getUserTable() {
		if (userTable == null) {
			userTable = new JTable();
			userTable.setModel(new UserTableModel());
			userTable.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {

					JPopupMenu popupMenu = getRightPopupMenu();
					if (e.getButton() == MouseEvent.BUTTON1) {
						int selectedRow = userTable.getSelectedRow();
						UserTableModel model = (UserTableModel) userTable
								.getModel();
						usernameTextField.setText((String) model.getValueAt(
								selectedRow, 1));
						PasswordField.setText((String) model.getValueAt(
								selectedRow, 2));

						if (((String) model.getValueAt(selectedRow, 3))
								.equals("m")) {
							maleRadioButton.setSelected(true);
						} else {
							femaleRadioButton.setSelected(true);
						}
						SimpleDateFormat format = new SimpleDateFormat(
								"yyyy-MM-dd");
						try {
							birthTextField.setDate(format.parse((String) model
									.getValueAt(selectedRow, 4)));
						} catch (ParseException e1) {
							// TODO 自动生成 catch 块
							e1.printStackTrace();
						}
						addressTextField.setText((String) model.getValueAt(
								selectedRow, 5));
						user_descTextField.setText((String) model.getValueAt(
								selectedRow, 6));
						System.out.println("left");

						deleteMenuItem.setEnabled(true);
					}
					if (e.getButton() == MouseEvent.BUTTON2) {
						System.out.println("middle");
					}
					if (e.getButton() == MouseEvent.BUTTON3) {
						System.out.println("right");
						popupMenu.show(userTable, e.getX(), e.getY());
					}
				}
			});
		}
		return userTable;
	}

	/**
	 * This method initializes userPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getUserPanel() {
		if (userPanel == null) {
			userPanel = new JPanel();
			userPanel.setLayout(new BorderLayout());
			userPanel.add(getMainScrollPane(), BorderLayout.CENTER);
			userPanel.add(getSearchPanel(), BorderLayout.NORTH);
			userPanel.add(getUserInfoPanel(), BorderLayout.SOUTH);
		}
		return userPanel;
	}

	/**
	 * This method initializes mainTabbedPane
	 * 
	 * @return javax.swing.JTabbedPane
	 */
	private JTabbedPane getMainTabbedPane() {
		if (mainTabbedPane == null) {
			mainTabbedPane = new JTabbedPane();
			mainTabbedPane.addTab("用户管理", null, getUserPanel(), null);
			mainTabbedPane.addTab("图书管理", null, getBookPanel1(), null);
		}
		return mainTabbedPane;
	}

	/**
	 * This method initializes searchPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getSearchPanel() {
		if (searchPanel == null) {
			FlowLayout flowLayout1 = new FlowLayout();
			flowLayout1.setAlignment(FlowLayout.LEFT);
			jLabel = new JLabel();
			jLabel.setText("输入要查询的用户名");
			jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
			jLabel.setHorizontalAlignment(SwingConstants.CENTER);
			searchPanel = new JPanel();
			searchPanel.setLayout(flowLayout1);
			searchPanel.add(jLabel, null);
			searchPanel.add(getSearchTextField(), null);
			searchPanel.add(getSearchButton(), null);
		}
		return searchPanel;
	}

⌨️ 快捷键说明

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