`
yujia123
  • 浏览: 33480 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

酒店管理系统之登录界面(swing)

阅读更多

package com.mwq.frame;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.net.URL;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;

import com.mwq.dao.Dao;
import com.mwq.mwing.MPanel;

public class LandFrame extends JFrame {

	private JPasswordField passwordField;// 密码框

	private JComboBox usernameComboBox;// 用户名下拉菜单

	public static void main(String args[]) {
		try {
			LandFrame frame = new LandFrame();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public LandFrame() {
		// 首先设置窗口的相关信息
		super();// 调用父类的构造方法
		setTitle(" T 科技");// 设置窗口的标题
		setResizable(false);// 设置窗口不可以改变大小
		setAlwaysOnTop(true);// 设置窗口总在最前方
		setBounds(100, 100, 428, 292);// 设置窗口的大小
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置当关闭窗口时执行的动作

		// 下面将创建一个面板对象并添加到窗口的容器中
		final MPanel panel = new MPanel(this.getClass().getResource(
				"/img/land_background.jpg"));// 创建一个面板对象
		panel.setLayout(new GridBagLayout());// 设置面板的布局管理器为网格组布局
		getContentPane().add(panel, BorderLayout.CENTER);// 将面板添加到窗体中

		final JLabel topLabel = new JLabel();
		topLabel.setPreferredSize(new Dimension(0, 126));
		final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
		gridBagConstraints_5.gridx = 0;
		gridBagConstraints_5.gridy = 0;
		panel.add(topLabel, gridBagConstraints_5);

		final JLabel leftLabel = new JLabel();
		leftLabel.setPreferredSize(new Dimension(140, 0));
		final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints();
		gridBagConstraints_3.gridy = 1;
		gridBagConstraints_3.gridx = 0;
		panel.add(leftLabel, gridBagConstraints_3);

		final JLabel rightLabel = new JLabel();
		rightLabel.setPreferredSize(new Dimension(55, 0));
		final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
		gridBagConstraints_2.gridy = 1;
		gridBagConstraints_2.gridx = 1;
		panel.add(rightLabel, gridBagConstraints_2);

		// 创建并设置用户名下拉菜单
		usernameComboBox = new JComboBox();// 创建用户名下拉菜单组件对象
		usernameComboBox.setMaximumRowCount(5);// 设置下拉菜单最多可显示的选项数
		usernameComboBox.addItem("请选择");// 为下拉菜单添加提示项
		usernameComboBox
				.addActionListener(new UsernameComboBoxActionListener());// 为下拉菜单添加事件监听器
		final GridBagConstraints gridBagConstraints = new GridBagConstraints();// 创建网格组布局管理器对象
		gridBagConstraints.anchor = GridBagConstraints.WEST;// 设置为靠左侧显示
		gridBagConstraints.gridy = 1;// 设置行索引为1
		gridBagConstraints.gridx = 2;// 设置列索引为2
		panel.add(usernameComboBox, gridBagConstraints);// 将组件按指定的布局管理器添加到面板中

		// 创建并设置密码框
		passwordField = new JPasswordField();// 创建密码框组件对象
		passwordField.setColumns(20);// 设置密码框可显示的字符数
		passwordField.setText("      ");// 设置密码框默认显示6个空格
		passwordField.addFocusListener(new PasswordFieldFocusListener());// 为密码框添加焦点监听器
		final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();// 创建网格组布局管理器对象
		gridBagConstraints_1.insets = new Insets(5, 0, 0, 0);// 设置组件外部上方的填充量为5像素
		gridBagConstraints_1.anchor = GridBagConstraints.WEST;// 设置为靠左侧显示
		gridBagConstraints_1.gridy = 2;// 设置行索引为2
		gridBagConstraints_1.gridx = 2;// 设置列索引为2
		panel.add(passwordField, gridBagConstraints_1);// 将组件按指定的布局管理器添加到面板中

		// 创建并设置一个用来添加三个按钮的面板
		final JPanel buttonPanel = new JPanel();// 创建一个用来添加按钮的面板
		buttonPanel.setOpaque(false);// 设置面板的背景为透明
		buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));// 设置面板采用水平箱布局
		final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();// 创建网格组布局管理器对象
		gridBagConstraints_4.insets = new Insets(10, 0, 0, 0);// 设置组件外部上方的填充量为10像素
		gridBagConstraints_4.gridwidth = 2;// 设置其占两列
		gridBagConstraints_4.gridy = 3;// 设置行索引为3
		gridBagConstraints_4.gridx = 1;// 设置列索引为1
		panel.add(buttonPanel, gridBagConstraints_4);// 将组件按指定的布局管理器添加到面板中

		// 创建并设置一个登录按钮,并将其添加到用来添加按钮的面板中
		final JButton landButton = new JButton();// 创建登录按钮组件对象
		landButton.setMargin(new Insets(0, 0, 0, 0));// 设置按钮边框和标签之间的间隔
		landButton.setContentAreaFilled(false);// 设置不绘制按钮的内容区域
		landButton.setBorderPainted(false);// 设置不绘制按钮的边框
		URL landUrl = this.getClass().getResource("/img/land_submit.png");// 获得默认情况下登录按钮显示图片的URL
		landButton.setIcon(new ImageIcon(landUrl));// 设置默认情况下登录按钮显示的图片
		URL landOverUrl = this.getClass().getResource(
				"/img/land_submit_over.png");// 获得当鼠标经过登录按钮时显示图片的URL
		landButton.setRolloverIcon(new ImageIcon(landOverUrl));// 设置当鼠标经过登录按钮时显示的图片
		URL landPressedUrl = this.getClass().getResource(
				"/img/land_submit_pressed.png");// 获得当登录按钮被按下时显示图片的URL
		landButton.setPressedIcon(new ImageIcon(landPressedUrl));// 设置当登录按钮被按下时显示的图片
		landButton.addActionListener(new LandButtonActionListener());// 为登录按钮添加事件监听器
		buttonPanel.add(landButton);// 将登录按钮添加到用来添加按钮的面板中

		final JButton resetButton = new JButton();
		resetButton.setMargin(new Insets(0, 0, 0, 0));
		resetButton.setContentAreaFilled(false);
		resetButton.setBorderPainted(false);
		URL resetUrl = this.getClass().getResource("/img/land_reset.png");
		resetButton.setIcon(new ImageIcon(resetUrl));
		URL resetOverUrl = this.getClass().getResource(
				"/img/land_reset_over.png");
		resetButton.setRolloverIcon(new ImageIcon(resetOverUrl));
		URL resetPressedUrl = this.getClass().getResource(
				"/img/land_reset_pressed.png");
		resetButton.setPressedIcon(new ImageIcon(resetPressedUrl));
		resetButton.addActionListener(new ResetButtonActionListener());
		buttonPanel.add(resetButton);

		final JButton exitButton = new JButton();
		exitButton.setMargin(new Insets(0, 0, 0, 0));
		exitButton.setContentAreaFilled(false);
		exitButton.setBorderPainted(false);
		URL exitUrl = this.getClass().getResource("/img/land_exit.png");
		exitButton.setIcon(new ImageIcon(exitUrl));
		URL exitOverUrl = this.getClass()
				.getResource("/img/land_exit_over.png");
		exitButton.setRolloverIcon(new ImageIcon(exitOverUrl));
		URL exitPressedUrl = this.getClass().getResource(
				"/img/land_exit_pressed.png");
		exitButton.setPressedIcon(new ImageIcon(exitPressedUrl));
		exitButton.addActionListener(new ExitButtonActionListener());
		buttonPanel.add(exitButton);
		//

		// 初始化用户名下拉菜单
		Vector userNameV = Dao.getInstance().sUserNameOfNotFreeze();
		if (userNameV.size() == 0) {
			usernameComboBox.addItem("TSoft");
		} else {
			for (int i = 0; i < userNameV.size(); i++) {
				usernameComboBox.addItem(userNameV.get(i));
			}
		}

	}

	class UsernameComboBoxActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String userName = (String) usernameComboBox.getSelectedItem();
			if (userName.equals("TSoft"))
				passwordField.setText("111");
		}
	}

	class PasswordFieldFocusListener implements FocusListener {
		public void focusGained(FocusEvent e) {
			passwordField.setText("");
		}

		public void focusLost(FocusEvent e) {
			char[] passwords = passwordField.getPassword();
			String password = turnCharsToString(passwords);
			if (password.length() == 0) {
				passwordField.setText("      ");
			}
		}
	}

	class ExitButtonActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			System.exit(0);
		}
	}

	class ResetButtonActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			usernameComboBox.setSelectedIndex(0);
			passwordField.setText("      ");
		}
	}

	class LandButtonActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String username = usernameComboBox.getSelectedItem().toString();// 获得登录用户的名称
			if (username.equals("请选择")) {// 查看是否选择了登录用户
				JOptionPane.showMessageDialog(null, "请选择登录用户!", "友情提示",
						JOptionPane.INFORMATION_MESSAGE);// 弹出提示
				resetUsernameAndPassword();// 恢复登录用户和登录密码
			}
			char[] passwords = passwordField.getPassword();// 获得登录用户的密码
			String inputPassword = turnCharsToString(passwords);// 将密码从char型数组转换成字符串
			if (username.equals("TSoft")) {// 查看是否为默认用户登录
				if (inputPassword.equals("111")) {// 查看密码是否为默认密码
					land(null);// 登录成功
					String infos[] = { "请立刻单击“用户管理”按钮添加用户!",
							"添加用户后需要重新登录,本系统才能正常使用!" };// 组织提示信息
					JOptionPane.showMessageDialog(null, infos, "友情提示",
							JOptionPane.INFORMATION_MESSAGE);// 弹出提示
				} else {// 密码错误
					JOptionPane.showMessageDialog(null,
							"默认用户“TSoft”的登录密码为“111”!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);// 弹出提示
					passwordField.setText("111");// 将密码设置为默认密码
				}
			} else {
				if (inputPassword.length() == 0) {// 用户未输入登录密码
					JOptionPane.showMessageDialog(null, "请输入登录密码!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);// 弹出提示
					resetUsernameAndPassword();// 恢复登录用户和登录密码
				}
				Vector user = Dao.getInstance().sUserByName(username);// 查询登录用户
				String password = user.get(5).toString();// 获得登录用户的密码
				if (inputPassword.equals(password)) {// 查看登录密码是否正确
					land(user);// 登录成功
				} else {// 登录密码错误
					JOptionPane.showMessageDialog(null, "登录密码错误,请确认后重新登录!",
							"友情提示", JOptionPane.INFORMATION_MESSAGE);// 弹出提示
					resetUsernameAndPassword();// 恢复登录用户和登录密码
				}
			}
		}

		private void resetUsernameAndPassword() {// 恢复登录用户和登录密码
			usernameComboBox.setSelectedIndex(0);// 恢复选中的登录用户为“请选择”项
			passwordField.setText("      ");// 恢复密码框的默认值为6个空格
			return;// 直接返回
		}

		private void land(Vector user) {// 登录成功
			TipWizardFrame tipWizard = new TipWizardFrame(user);// 创建主窗体对象
			tipWizard.setVisible(true);// 设置主窗体可见
			setVisible(false);// 设置登录窗口不可见
		}

	}

	private String turnCharsToString(char[] chars) {
		StringBuffer strBuf = new StringBuffer();
		for (int i = 0; i < chars.length; i++) {
			strBuf.append(chars[i]);
		}
		return strBuf.toString().trim();
	}
}



上面代码得出如下图:



在53行:
final MPanel panel = new MPanel(this.getClass().getResource(
用到下面代码:
package com.mwq.mwing;

import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class MPanel extends JPanel {

	private ImageIcon imageIcon;// 声明一个图片对象

	public MPanel(URL imgUrl) {
		super();// 继承父类的构造方法
		setLayout(new GridBagLayout());// 将布局管理器修改为网格组布局
		imageIcon = new ImageIcon(imgUrl);// 根据传入的URL创建ImageIcon对象
		setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());// 设置面板与图片等大
	}

	protected void paintComponent(Graphics g) {// 重写JPanel类的paintComponent()方法
		super.paintComponent(g);// 调用JPanel类的paintComponent()方法
		Image image = imageIcon.getImage();// 通过ImageIcon对象获得Image对象
		g.drawImage(image, 0, 0, null);// 绘制Image对象,即将图片绘制到面板中
	}

}


  • 大小: 31.6 KB
分享到:
评论
1 楼 guzhixiong 2012-03-17  
楼主很强大,需要向楼主学习,到时候有不会的向楼主请教

相关推荐

    课程设计-基于Java swing带GUI界面的酒店管理系统(源码+SQL SERVER数据库+配置说明).zip

    酒店管理系统的需求包括开台点菜功能、智能化获取菜品功能、自动结账功能、营业额报表功能等。依据餐饮行业的特点,本系统实现以下目标: 操作简单方便、界面简洁大方。 方便快捷的开台点菜功能。 智能化定位...

    javaswing酒店管理系统源代码+数据库模型

    javaswing酒店管理系统源代码+数据库模型 酒店管理系统的需求包括开台点菜功能、智能化获取菜品功能、自动结账功能、营业额报表功能等。依据餐饮行业的特点,本系统实现以下目标: 操作简单方便、界面简洁大方。 ...

    基于JavaSwing+Mysql酒店管理系统

    项目是使用Java swing开发,可实现基础数据维护用户登录、系统首页酒店信息管理、主要模块是开房管理、退房管理、房间信息管理、顾客信息管理等功能。界面设计比较简介、适合作为Java课设设计以及学习技术使用。

    基于Java swing带GUI界面的酒店宾馆管理系统源码+数据库(95分以上课设).zip

    基于Java swing带GUI界面的酒店管理系统源码+数据库(95分以上课设).zip 代码完整下载即用无需修改。 基于Java swing带GUI界面的酒店管理系统源码+数据库(95分以上课设).zip 代码完整下载即用无需修改。基于...

    swing 酒店管理系统源码

    图1.7 酒店管理系统主界面 (1)单击“用户管理”按钮,对用户信息进行添加及删除操作。 (2)单击“修改密码”按钮,修改当前登录的用户密码操作。 (3)单击“台号管理”按钮,对台号信息进行添加、查询及删除操作...

    酒店管理系统.docx

    酒店管理系统实现功能:登录界面模块:通过使用Java swing组件编写的比较友好的登录界面,同时也包括了通过JDBC连接数据库查询管理员的信息,数据库中的管理员表,正确输入密码和用户名才能尽进行登录。使用主界面,...

    java课设之征名管理系统Swing图形化界面

    java课设之征名管理系统,用swing做的全部界面,内含完整程序源码以及详细注释,课程设计要求,软件需求 分析说明书,课程设计总结报告,活动图、软件原型、用例图的全部原图,已生成jar包和javadoc文档,软件需求...

    基于Swing技术下的酒店客房信息管理系统源码+数据库+WORD毕业论文文档.zip

    系统基于JAVA的Application模式,使用Swing组件作为系统用户界面和MYSQL小型数据库管理系统实现。主要提供用户查询功能、住宿管理等功能,提供管理员客房、用户、系统信息的管理功能。 该系统遵循软件工程中的开发...

    javaSwing+Mysql酒店管理系统

    项目是使用Java swing开发,可实现基础数据维护用户登录、系统首页酒店信息管理、主要模块是开房管理、退房管理、房间信息管理、顾客信息管理等功能。界面设计比较简介、适合作为Java课设设计以及学习技术使用。 ...

    Java 酒店管理系统 -Swing界面 access数据库

    系统的主要功能围绕系统登录,房间管理,用户管理展开。 用户通过登录窗体进入系统主界面。系统主界面可以通向房间管理界面,住房登记界面,退房登记界面。主界面通过表格简单的展示了客房的状态与当前顾客的基本...

    javaswing实现宾馆管理信息系统源码(含数据库).rar

    ava实现宾馆管理信息系统,数据库mysql,数据库课程设计,ui使用swing 管理员账号:Admin 管理员密码是空 除此之外,其它用户的密码均和账号相同

    酒店管理系统 | java课程设计 | 大学生毕业设计 | 酒店信息管理系统 | swing界面

    酒店信息管理系统,大学生学习专用,毕业设计和课程设计都可以作为参考,swing界面,下载下来可以直接使用。 使用方法: 在使用前,需要到druid.properties 配置文件中,修改自己对应于自己数据库的属性;如用户名,...

    java swing精品项目源码第1期:酒店管理系统.zip

    资源名:java swing精品项目源码第1期:酒店管理系统.zip 资源类型:项目全套源码+技术文档+使用说明+界面截图+讲解视频 源码说明: 全部项目源码都是经过测试校正后百分百成功运行的,如果您下载后不能运行可联系我...

    酒店管理系统JAVA源代码

    酒店管理系统使用说明书 主要功能 本系统中包含如下6大功能模块: q 前台服务:该模块主要包括开台点菜、维护菜品、签单、结账等功能,其中维护菜品功能包括添加和取消菜品,能够取消菜品的前提条件是尚未签单,即...

    基于Swing技术下的酒店客房信息管理系统源码含文档.zip

    系统基于JAVA的Application模式,使用Swing组件作为系统用户界面和MYSQL小型数据库管理系统实现。主要提供用户查询功能、住宿管理等功能,提供管理员客房、用户、系统信息的管理功能。 该系统遵循软件工程中的开发...

    java 酒店管理系统

    java 酒店管理系统 swing图形界面做得很漂亮

    Java+Swing+SQL+Server2005开发酒店管理系统

    酒店管理系统+Java+Swing+SQL+Server2005 Java+Swing+SQL+Server2005开发酒店管理系统源代码下载 系统介绍 酒店管理系统的需求包括开台点菜功能、智能化获取菜品功能、自动结账功能、营业额报表功能等。依据餐饮...

    Java课程设计报告-基于swing带GUI界面的宾馆信息管理系统.doc

    1.要求在前台主界面上显示数据库中存放的房客和房间的基本信息,由特定权限的管理员或者用户登录后通过按钮或菜单实现客户订房、退房、换房和用户添加、修改、删除、查询客房信息等一系列操作。2.利用JDBC驱动程序...

    java swing mysql实现的酒店管理系统项目源码,Java语言,代码源文件,毕业设计

    基于Java Swing和MySQL的酒店管理系统的设计与实现 简介:本文档描述了一个基于Java Swing和MySQL的酒店管理系统的设计和实现。该系统旨在提高酒店服务效率和客户满意度,实现酒店管理的自动化和信息化。本文分析了...

    酒店管理系统(ppt+ER图+流程图+ )_基于java swing管理系统源码 程序 代码 图形界面.rar

    酒店管理系统(ppt+ER图+流程图+ )_基于java swing管理系统源码 程序 代码 图形界面.rar

Global site tag (gtag.js) - Google Analytics