您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页java酒店管理系统课程设计

java酒店管理系统课程设计

来源:意榕旅游网
Java语言程序设计课程设计

题 目 酒店管理系统 学 院 南湖学院 专 业 计算机科学与技术 班 级 计科N112 学 号

学生姓名 吴威宗 指导教师 李永刚 编写日期 2014/6/26

目录

一、需求分析 ............................................................................................................................. 二、系统运行环境 ..................................................................................................................... 三、功能需求描述 ..................................................................................................................... 四、模块结构图 ......................................................................................................................... 五、数据库设计 ......................................................................................................................... 5.1数据库分析 .................................................................................................................... 5.2数据库概念设计 ............................................................................................................ 5.3 数据库逻辑结构设计 ................................................................................................... 六、程序模块设计 ..................................................................................................................... 七、总结 .....................................................................................................................................

一、需求分析

随着餐饮行业的迅速发展,现有的人工管理方式已经不能呢个满足管理者的需求,广大餐饮业经营者已经意识到使用计算机应用软件的重要性,决定在餐饮

企业的经营管理上引入计算机应用软件管理系统。

酒店管理系统的大致功能:

1. 开台点餐 2. 菜品管理 3. 自动结账

4. 后台菜系菜品管理 5. 日月年结账报表 6. 用户设置

根据需求分析,本系统采用的语言:

(1)本系统采用Java语言,Java是目前使用最为广泛的计算机语言之一。它具有简单,面向对象,稳定,与平台无关等特点。说他简单,并不是说这门语言很干瘪,而是一种清楚更容易理解的方式实现程序。面向对象是基于对象的变成更符合人的思维方式,使人们更容易编写程序。

(2)本系统还采用SQL语言,SQL Server具有许多显着优点:易用性、适合分布组织的可伸缩性、用于决策支持的数据仓库功能、与许多其他服务器软件紧密关联的集成性、良好的性价比等。

(3) 本系统有效的利用Java和SQL的优点。

二、系统运行环境

操作系统为Windows 7、windows XP或windows 2003 使用的集成开发工具Eclipse 数据库采用SQL Server2008,项目运行环境为JDK 7。

三、功能需求描述

1.开台签单工作区的功能:主要功能有开台、点菜、加菜、签单、查看开台信息和签单信息。

2.自动结账工作区的功能:一个功能是自动计算当前选中餐台的消费金额;另一个功能是在结账时自动计算找零金额。

3.结账报表工作区功能:日结帐报表,月结账报表,年结账报表。 4.后天管理工作区功能:管理添加信息

四、模块结构图

模块结构图

五、数据库设计

5.1数据库分析

酒店管理系统的需求包括开台点菜功能、智能化获取菜品功能、自动结账功能、营业额报表功能等。在这些功能总主要涉及的数据表包括台号表、菜品表、消费单表;为了使系统更加的完善,还需要为菜品分类,即需要用到菜系表;为了实现菜品的日销售情况统计,还要建立一个消费项目表,用来记录消费单消费的菜品。

5.2数据库概念设计

数据库设计是系统设计过程中的重要组成部分,它是通过管理系统的整天需求而制定的,数据库设计的好坏直接影响到系统的后期开发。

5.3 数据库逻辑结构设计

台号表

菜品表 菜系表 消费单表 消费项目表 管理员表

六、程序模块设计

功能模块整体设计:

用户功能界面:

代码:

public class LandFrame extends JFrame {

private JPasswordField passwordField;// 密码框 private JComboBox usernameComboBox;// 用户名下拉菜单 public static void main(String args[]) { }

public LandFrame() {

try {

LandFrame frame = new LandFrame(); frame.setVisible(true);

} catch (Exception e) { }

e.printStackTrace();

// 首先设置窗口的相关信息 super();// 调用父类的构造方法

setTitle(\" 小组:吴威宗 周志远\");// 设置窗口的标题 setResizable(false);// 设置窗口不可以改变大小 setAlwaysOnTop(true);// 设置窗口总在最前方 setBounds(100, 100, 428, 292);// 设置窗口的大小

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置当关闭

窗口时执行的动作

// 下面将创建一个面板对象并添加到窗口的容器中

final MPanel panel = new MPanel(this.getClass().getResource(

\"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();

对象

usernameComboBox.setMaximumRowCount(5);// 设置下拉菜单最多可

gridBagConstraints_2.gridy = 1; gridBagConstraints_2.gridx = 1;

panel.add(rightLabel, gridBagConstraints_2); // 创建并设置用户名下拉菜单

usernameComboBox = new JComboBox();// 创建用户名下拉菜单组件

显示的选项数

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);// 将组件按指定

的布局管理器添加到面板中

对象

landButton.setMargin(new Insets(0, 0, 0, 0));// 设置按钮边框

// 创建并设置一个登录按钮,并将其添加到用来添加按钮的面板中 final JButton landButton = new JButton();// 创建登录按钮组件

和标签之间的间隔

landButton.setContentAreaFilled(false);// 设置不绘制按钮的内

容区域

landButton.setBorderPainted(false);// 设置不绘制按钮的边框 URL landUrl =

this.getClass().getResource(\"land_submit.png\");// 获得默认情况下登录按钮显示图片的URL

landButton.setIcon(new ImageIcon(landUrl));// 设置默认情况下

登录按钮显示的图片

URL landOverUrl = this.getClass().getResource(

\"land_submit_over.png\");// 获得当鼠标经过登录按钮时显

示图片的URL

landButton.setRolloverIcon(new

ImageIcon(\"land_submit_over.png\"));// 设置当鼠标经过登录按钮时显示的图片

URL landPressedUrl = this.getClass().getResource(

\"land_submit_pressed.png\");// 获得当登录按钮被按下时显

示图片的URL

landButton.setPressedIcon(new

ImageIcon(\"land_submit_pressed.png\"));// 设置当登录按钮被按下时显示的图片

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(\"land_reset.png\"); resetButton.setIcon(new ImageIcon(resetUrl)); URL resetOverUrl = this.getClass().getResource(

\"land_reset_over.png\");

resetButton.setRolloverIcon(new

ImageIcon(\"land_reset_over.png\"));

URL resetPressedUrl = this.getClass().getResource(

\"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(\"land_exit.png\"); exitButton.setIcon(new ImageIcon(exitUrl)); URL exitOverUrl = this.getClass()

.getResource(\"land_exit_over.png\");

exitButton.setRolloverIcon(new ImageIcon(exitOverUrl)); URL exitPressedUrl = this.getClass().getResource(

\"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();

}

class PasswordFieldFocusListener implements FocusListener { }

class ExitButtonActionListener implements ActionListener {

public void actionPerformed(ActionEvent arg0) { public void focusGained(FocusEvent e) { }

public void focusLost(FocusEvent e) { }

char[] passwords = passwordField.getPassword(); String password = turnCharsToString(passwords); if (password.length() == 0) { }

passwordField.setText(\" \"); passwordField.setText(\"\"); }

if (userName.equals(\"TSoft\"))

passwordField.setText(\"111\");

}

}

System.exit(0);

class ResetButtonActionListener implements ActionListener { }

class LandButtonActionListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

String username =

public void actionPerformed(ActionEvent arg0) { }

usernameComboBox.setSelectedIndex(0); passwordField.setText(\" \");

usernameComboBox.getSelectedItem().toString();// 获得登录用户的名称

if (username.equals(\"请选择\")) {// 查看是否选择了登录用户

JOptionPane.showMessageDialog(null, \"请选择登录用户!\

\"友情提示\

}

char[] passwords = passwordField.getPassword();// 获得登录

JOptionPane.INFORMATION_MESSAGE);// 弹出提示

resetUsernameAndPassword();// 恢复登录用户和登录密码

用户的密码

String inputPassword = turnCharsToString(passwords);// 将

密码从char型数组转换成字符串

if (username.equals(\"JAVA\")) {// 查看是否为默认用户登录

if (inputPassword.equals(\"123456\")) {// 查看密码是否为

默认密码

land(null);// 登录成功

String infos[] = { \"请立刻单击“用户管理”按钮添加用

户!\

\"添加用户后需要重新登录,本系统才能正常使用!

\" };// 组织提示信息

\

JOptionPane.INFORMATION_MESSAGE);// 弹出提示

JOptionPane.showMessageDialog(null, infos, \"友情提示

} else {// 密码错误

JOptionPane.showMessageDialog(null,

\"默认用户“TSoft”的登录密码为“111”!\友

情提示\

}

JOptionPane.INFORMATION_MESSAGE);// 弹出提示

passwordField.setText(\"111\");// 将密码设置为默认密

} else {

if (inputPassword.length() == 0) {// 用户未输入登录密码

JOptionPane.showMessageDialog(null, \"请输入登录密

码!\友情提示\

}

Vector user = Dao.getInstance().sUserByName(username);//

JOptionPane.INFORMATION_MESSAGE);// 弹出提示

resetUsernameAndPassword();// 恢复登录用户和登录密

查询登录用户

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

个空格

}

private void land(Vector user) {// 登录成功

TipWizardFrame tipWizard = new TipWizardFrame(user);// 创return;// 直接返回

建主窗体对象

}

private String turnCharsToString(char[] chars) {

StringBuffer strBuf = new StringBuffer(); for (int i = 0; i < chars.length; i++) { }

return strBuf.toString().trim();

strBuf.append(chars[i]); }

tipWizard.setVisible(true);// 设置主窗体可见 setVisible(false);// 设置登录窗口不可见

}

}

数据库连接代码:

public class JDBC {

private String dbUserName=\"root\"; private String dbPassword=\"123456\"; /**

获取数据库连接 **/

public Connection getCon() throws Exception{ Class.forName(jdbcName);

Connection con=DriverManager.getConnection(JDBC, dbUserName,dbPassword);

return con; } /*

* 关闭数据库连接 * * */

public void closeCon(Connection con) throws Exception{

if(con!=null){ con.close();

}

}

public static void main(String[]args){

JDBC JDBC =new JDBC() ; try {

JDBC.getCon();

} catch (Exception e) { }

// TODO Auto-generated catch block e.printStackTrace();

}

public static Connection getConnection() { } }

// TODO Auto-generated method stub return null;

日期类代码:

package import

public class Today {

private static final Calendar NOW = Calendar.getInstance(); private static final int YEAR = NOW.get(Calendar.YEAR); private static final int MONTH = NOW.get(Calendar.MONTH) + 1; private static final int DAY = NOW.get(Calendar.DAY_OF_MONTH); private static final int WEEK = NOW.get(Calendar.DAY_OF_WEEK); private static final int HOUR = NOW.get(Calendar.HOUR_OF_DAY); private static final int MINUTE = NOW.get(Calendar.MINUTE); private static final int SECOND = NOW.get(Calendar.SECOND);

//

public static String getDate() { }

public static String getDateOfNum() { }

public static String getDateOfShow() { }

public static String getDayOfWeek() { }

public static String getTime() {

return HOUR + \":\" + MINUTE + \":\" + SECOND; String dayOfWeek = \"\"; switch (WEEK) { case 1: }

return dayOfWeek;

dayOfWeek = \"星期日\"; break;

dayOfWeek = \"星期一\"; break;

dayOfWeek = \"星期二\"; break;

dayOfWeek = \"星期三\"; break;

dayOfWeek = \"星期四\"; break;

dayOfWeek = \"星期五\"; dayOfWeek = \"星期六\"; break;

return YEAR + \"年\" + MONTH + \"月\" + DAY + \"日\"; String y = YEAR + \"\"; String m = MONTH + \"\"; String d = DAY + \"\"; if (MONTH < 10)

m = \"0\" + MONTH; d = \"0\" + DAY; if (DAY < 10) return y + m + d;

return YEAR + \"-\" + MONTH + \"-\" + DAY;

case 2:

case 3:

case 4:

case 5:

case 6: case 7:

}

public static void main(String[] args) { }

public static int getYEAR() { }

public static int getDAY() { }

public static int getMONTH() { } }

return MONTH; return DAY; return YEAR;

System.out.println(Today.getDayOfWeek());

利用正则表达式验证数据合法性的方法代码:

public class Validate {

public static boolean execute(String rule, String content) { } }

Pattern pattern = Pattern.compile(rule);// 利用验证规则创建Pattern对象 Matcher matcher = pattern.matcher(content);// 利用验证内容获得Matcher对象 return matcher.matches();// 返回验证结果

按钮类:

public class MButton extends JButton { }

public MButton() { }

setContentAreaFilled(false); setMargin(new Insets(0, 0, 0, 0)); setBorderPainted(false); setFocusPainted(false);

表格类:

public class MTable extends JTable {

{

/** * */

public MTable() { }

public MTable(DefaultTableModel tableModel) { }

// 表格列值居中显示 @Override

public TableCellRenderer getDefaultRenderer(Class columnClass)

super(tableModel); super();

// 获得除表格头部分的单元格对象

DefaultTableCellRenderer tableRenderer =

(DefaultTableCellRenderer) super

tableRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTE

.getDefaultRenderer(columnClass);

// 设置单元格内容居中显示

R);

return tableRenderer;

}

// 表格列名信息 @Override

public JTableHeader getTableHeader() {

// 获得表格头对象

JTableHeader tableHeader = super.getTableHeader();

tableHeader.setReorderingAllowed(false);// 设置表格列不可重

// 获得表格头的单元格对象

DefaultTableCellRenderer headerRenderer =

(DefaultTableCellRenderer) tableHeader

headerRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENT

.getDefaultRenderer();

// 设置单元格内容(即列名)居中显示

ER);

}

}

public void setRowSelectionInterval(int i) { }

// TODO Auto-generated method stub return tableHeader;

图片类:

public class MPanel extends JPanel { 局

imageIcon = new ImageIcon(imgUrl);// 根据传入的URL创建private ImageIcon imageIcon;// 声明一个图片对象 public MPanel(URL imgUrl) {

super();// 继承父类的构造方法

setLayout(new GridBagLayout());// 将布局管理器修改为网格组布

ImageIcon对象

setSize(imageIcon.getIconWidth(),

imageIcon.getIconHeight());// 设置面板与图片等大

}

protected void paintComponent(Graphics g) {// 重写JPanel类的

paintComponent()方法

Image image = imageIcon.getImage();// 通过ImageIcon对象获得

super.paintComponent(g);// 调用JPanel类的paintComponent()方

Image对象

g.drawImage(image, 0, 0, null);// 绘制Image对象,即将图片绘

制到面板中

}

}

修改密码对话框:

public class UpdatePasswordDialog extends JDialog {

private JPasswordField oldPasswordField; private JPasswordField repeatPasswordField; private JPasswordField newPasswordField; private final Dao dao = Dao.getInstance(); private Vector user; /**

* Launch the application *

* @param args */

public static void main(String args[]) {

try {

UpdatePasswordDialog dialog = new UpdatePasswordDialog(); dialog.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) { }

System.exit(0);

});

dialog.setVisible(true);

} catch (Exception e) {

}

}

e.printStackTrace();

/**

* Create the dialog */

public UpdatePasswordDialog() {

super();

getContentPane().setLayout(new GridBagLayout()); setModal(true); setTitle(\"修改密码\"); Dimension screenSize =

Toolkit.getDefaultToolkit().getScreenSize();

/ 2,

300, 200);

setBounds((screenSize.width - 300) / 2, (screenSize.height - 200)

final JLabel oldPasswordLabel = new JLabel(); oldPasswordLabel.setText(\"原 密 码:\");

final GridBagConstraints gridBagConstraints_7 = new

GridBagConstraints();

gridBagConstraints_7.gridx = 0; gridBagConstraints_7.gridy = 0;

getContentPane().add(oldPasswordLabel, gridBagConstraints_7); oldPasswordField = new JPasswordField(); oldPasswordField.setText(\" \");

oldPasswordField.addFocusListener(new FocusListener() {

public void focusGained(FocusEvent e) { }

public void focusLost(FocusEvent e) { }

char[] passwords = oldPasswordField.getPassword(); String password = turnCharsToString(passwords); if (password.length() == 0) { }

oldPasswordField.setText(\" \"); oldPasswordField.setText(\"\");

});

oldPasswordField.setColumns(25);

final GridBagConstraints gridBagConstraints_8 = new

GridBagConstraints();

gridBagConstraints_8.gridwidth = 3; gridBagConstraints_8.gridy = 0; gridBagConstraints_8.gridx = 1;

getContentPane().add(oldPasswordField, gridBagConstraints_8);

final JLabel newPasswordLabel = new JLabel(); newPasswordLabel.setText(\"新 密 码:\");

final GridBagConstraints gridBagConstraints = new

GridBagConstraints();

gridBagConstraints.insets = new Insets(10, 0, 0, 0); gridBagConstraints.gridy = 1; gridBagConstraints.gridx = 0;

getContentPane().add(newPasswordLabel, gridBagConstraints); newPasswordField = new JPasswordField(); newPasswordField.setText(\" \");

newPasswordField.addFocusListener(new FocusListener() {

public void focusGained(FocusEvent e) { }

public void focusLost(FocusEvent e) { }

char[] passwords = newPasswordField.getPassword(); String password = turnCharsToString(passwords); if (password.length() == 0) { }

newPasswordField.setText(\" \"); newPasswordField.setText(\"\");

});

newPasswordField.setColumns(25);

final GridBagConstraints gridBagConstraints_1 = new

GridBagConstraints();

gridBagConstraints_1.insets = new Insets(10, 0, 0, 0); gridBagConstraints_1.gridwidth = 3; gridBagConstraints_1.gridy = 1; gridBagConstraints_1.gridx = 1;

getContentPane().add(newPasswordField, gridBagConstraints_1); final JLabel repeatPasswordLabel = new JLabel(); repeatPasswordLabel.setText(\"重新输入:\");

final GridBagConstraints gridBagConstraints_2 = new

GridBagConstraints();

gridBagConstraints_2.insets = new Insets(10, 0, 0, 0); gridBagConstraints_2.gridy = 2; gridBagConstraints_2.gridx = 0;

getContentPane().add(repeatPasswordLabel,

gridBagConstraints_2);

repeatPasswordField = new JPasswordField(); repeatPasswordField.setText(\" \");

repeatPasswordField.addFocusListener(new FocusListener() {

public void focusGained(FocusEvent e) {

repeatPasswordField.setText(\"\");

}

public void focusLost(FocusEvent e) { }

char[] passwords = repeatPasswordField.getPassword(); String password = turnCharsToString(passwords); if (password.length() == 0) { }

repeatPasswordField.setText(\" \");

});

repeatPasswordField.setColumns(25);

final GridBagConstraints gridBagConstraints_3 = new

GridBagConstraints();

gridBagConstraints_3.gridwidth = 3;

gridBagConstraints_3.insets = new Insets(10, 0, 0, 0); gridBagConstraints_3.gridy = 2; gridBagConstraints_3.gridx = 1;

getContentPane().add(repeatPasswordField,

gridBagConstraints_3);

final JLabel label = new JLabel();

label.setPreferredSize(new Dimension(30, 20)); final GridBagConstraints gridBagConstraints_6 = new

GridBagConstraints();

gridBagConstraints_6.gridy = 3; gridBagConstraints_6.gridx = 1;

getContentPane().add(label, gridBagConstraints_6); final JButton submitButton = new JButton();

submitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

char[] oldPasswords = oldPasswordField.getPassword(); String oldPassword = turnCharsToString(oldPasswords); char[] newPasswords = newPasswordField.getPassword(); String newPassword = turnCharsToString(newPasswords); char[] repeatPasswords =

repeatPasswordField.getPassword();

String repeatPassword =

turnCharsToString(repeatPasswords);

0

|| repeatPassword.length() == 0) {

if (oldPassword.length() == 0 || newPassword.length() ==

JOptionPane.showMessageDialog(null, \"请输入密码!\\"

友情提示\

JOptionPane.INFORMATION_MESSAGE);

oldPasswordField.setText(\" \"); newPasswordField.setText(\" \");

}

repeatPasswordField.setText(\" \"); return;

String password = user.get(5).toString(); if (oldPassword.equals(password)) {

\友情提示\

\友情提示\

if (newPassword.equals(repeatPassword)) { String username = user.get(1).toString(); user.set(5, newPassword);

dao.uPasswordByName(username, newPassword);

JOptionPane.showMessageDialog(null, \"密码修改成

JOptionPane.INFORMATION_MESSAGE);

dispose();

} else { JOptionPane.showMessageDialog(null,

\"您两次输入的新密码不一致,请确认后重新输

JOptionPane.INFORMATION_MESSAGE);

oldPasswordField.setText(\" \"); newPasswordField.setText(\" \"); repeatPasswordField.setText(\" \");

}

功!入!

} else {

JOptionPane.showMessageDialog(null, \"您输入的原密码

错误,请确认后重新输入!\

}

}

\"友情提示\

oldPasswordField.setText(\" \"); newPasswordField.setText(\" \"); repeatPasswordField.setText(\" \");

});

submitButton.setText(\"确定\");

final GridBagConstraints gridBagConstraints_4 = new

GridBagConstraints();

gridBagConstraints_4.insets = new Insets(10, 0, 0, 0); gridBagConstraints_4.gridy = 3; gridBagConstraints_4.gridx = 2;

getContentPane().add(submitButton, gridBagConstraints_4); final JButton exitButton = new JButton();

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { }

dispose();

});

exitButton.setText(\"退出\");

final GridBagConstraints gridBagConstraints_5 = new

GridBagConstraints();

}

用户管理对话框:

}

private String turnCharsToString(char[] chars) { }

public void setUser(Vector user) { }

this.user = user;

StringBuffer strBuf = new StringBuffer(); for (int i = 0; i < chars.length; i++) { }

return strBuf.toString().trim();

strBuf.append(chars[i]);

gridBagConstraints_5.insets = new Insets(10, 10, 0, 0); gridBagConstraints_5.gridy = 3; gridBagConstraints_5.gridx = 3;

getContentPane().add(exitButton, gridBagConstraints_5); //

public class UserManagerDialog extends JDialog {

private MTable table;

private Vector tableColumnV; private Vector tableValueV; private DefaultTableModel tableModel;

private ButtonGroup buttonGroup = new ButtonGroup(); private JTextField passwordTextField; private JTextField idCardTextField; private JTextField birthdayTextField; private JTextField nameTextField; private Dao dao = Dao.getInstance(); private boolean isAdd = true; /**

* Launch the application *

* @param args */

public static void main(String args[]) {

// try {

// UserManagerDialog dialog = new UserManagerDialog(); // dialog.addWindowListener(new WindowAdapter() { // public void windowClosing(WindowEvent e) {

}

// System.exit(0); // } // });

// dialog.setVisible(true); // } catch (Exception e) { // e.printStackTrace(); // }

/**

* Create the dialog */

public UserManagerDialog() {

super(); setModal(true); setTitle(\"用户管理\");

setBounds(100, 100, 500, 375);

final JPanel inputPanel = new JPanel(); inputPanel.setLayout(new GridBagLayout());

getContentPane().add(inputPanel, BorderLayout.NORTH); final JLabel nameLabel = new JLabel(); nameLabel.setText(\"姓 名:\");

final GridBagConstraints gridBagConstraints_13 = new

GridBagConstraints();

gridBagConstraints_13.insets = new Insets(10, 0, 0, 0); inputPanel.add(nameLabel, gridBagConstraints_13); nameTextField = new JTextField(); nameTextField.setColumns(12);

final GridBagConstraints gridBagConstraints = new

GridBagConstraints();

gridBagConstraints.insets = new Insets(10, 0, 0, 0); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 1;

inputPanel.add(nameTextField, gridBagConstraints); final JLabel sexLabel = new JLabel(); sexLabel.setText(\"性别:\");

final GridBagConstraints gridBagConstraints_1 = new

GridBagConstraints();

gridBagConstraints_1.insets = new Insets(10, 15, 0, 0); gridBagConstraints_1.gridy = 0; gridBagConstraints_1.gridx = 2;

inputPanel.add(sexLabel, gridBagConstraints_1);

final JRadioButton manRadioButton = new JRadioButton(); buttonGroup.add(manRadioButton); manRadioButton.setText(\"男\");

manRadioButton.setSelected(true);

final GridBagConstraints gridBagConstraints_2 = new

GridBagConstraints();

gridBagConstraints_2.insets = new Insets(10, 0, 0, 0); gridBagConstraints_2.gridy = 0; gridBagConstraints_2.gridx = 3;

inputPanel.add(manRadioButton, gridBagConstraints_2); final JRadioButton womanRadioButton = new JRadioButton(); buttonGroup.add(womanRadioButton); womanRadioButton.setText(\"女\");

final GridBagConstraints gridBagConstraints_3 = new

GridBagConstraints();

gridBagConstraints_3.insets = new Insets(10, 0, 0, 0); gridBagConstraints_3.gridy = 0; gridBagConstraints_3.gridx = 4;

inputPanel.add(womanRadioButton, gridBagConstraints_3); final JLabel birthdayLabel = new JLabel(); birthdayLabel.setText(\"出生日期:\");

final GridBagConstraints gridBagConstraints_4 = new

GridBagConstraints();

gridBagConstraints_4.insets = new Insets(10, 15, 0, 0); gridBagConstraints_4.gridy = 0;

gridBagConstraints_4.gridx = 5;

inputPanel.add(birthdayLabel, gridBagConstraints_4); birthdayTextField = new JTextField(); birthdayTextField.setColumns(20);

final GridBagConstraints gridBagConstraints_5 = new

GridBagConstraints();

gridBagConstraints_5.insets = new Insets(10, 0, 0, 0); gridBagConstraints_5.gridy = 0; gridBagConstraints_5.gridx = 6;

inputPanel.add(birthdayTextField, gridBagConstraints_5); final JLabel passwordLabel = new JLabel(); passwordLabel.setText(\"登录密码:\");

final GridBagConstraints gridBagConstraints_8 = new

GridBagConstraints();

gridBagConstraints_8.insets = new Insets(5, 0, 0, 0); gridBagConstraints_8.gridy = 1; gridBagConstraints_8.gridx = 0;

inputPanel.add(passwordLabel, gridBagConstraints_8); passwordTextField = new JTextField(); passwordTextField.setColumns(33);

final GridBagConstraints gridBagConstraints_9 = new

GridBagConstraints();

gridBagConstraints_9.gridwidth = 4;

gridBagConstraints_9.anchor = GridBagConstraints.WEST; gridBagConstraints_9.insets = new Insets(5, 0, 0, 0); gridBagConstraints_9.gridy = 1; gridBagConstraints_9.gridx = 1;

inputPanel.add(passwordTextField, gridBagConstraints_9); final JLabel idCardLabel = new JLabel(); idCardLabel.setText(\"身份证号:\");

final GridBagConstraints gridBagConstraints_6 = new

GridBagConstraints();

gridBagConstraints_6.insets = new Insets(5, 16, 0, 0); gridBagConstraints_6.gridy = 1; gridBagConstraints_6.gridx = 5;

inputPanel.add(idCardLabel, gridBagConstraints_6); idCardTextField = new JTextField(); idCardTextField.setColumns(20);

final GridBagConstraints gridBagConstraints_7 = new

GridBagConstraints();

gridBagConstraints_7.insets = new Insets(5, 0, 0, 0); gridBagConstraints_7.gridy = 1; gridBagConstraints_7.gridx = 6;

inputPanel.add(idCardTextField, gridBagConstraints_7);

final JPanel buttonPanel = new JPanel();

final GridBagConstraints gridBagConstraints_10 = new

GridBagConstraints();

gridBagConstraints_10.anchor = GridBagConstraints.EAST; gridBagConstraints_10.insets = new Insets(5, 0, 10, 0); gridBagConstraints_10.gridwidth = 7; gridBagConstraints_10.gridy = 2; gridBagConstraints_10.gridx = 0;

inputPanel.add(buttonPanel, gridBagConstraints_10); final JButton subButton = new JButton();

subButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String values[] = new String[6]; values[0] = nameTextField.getText();

values[1] = (manRadioButton.isSelected() ? \"男\" : \"女\"); values[2] = birthdayTextField.getText(); values[3] = idCardTextField.getText(); values[4] = passwordTextField.getText(); values[5] = \"正常\";

if (values[0].length() > 4) {

JOptionPane.showMessageDialog(null, \"姓名最多只能为

4 个汉字!\

}

\"友情提示\

nameTextField.setText(\"\"); nameTextField.requestFocus(); return;

if (!Validate.execute(\"[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\

values[2])) {

String infos[] = { \"出生日期输入错误!\\"正确格式为:

2008-8-8\" };

\

}

if (!Validate.execute(\"(\\\\d){1,18}\

String infos[] = { \"身份证号输入错误!\身份证号必

JOptionPane.INFORMATION_MESSAGE);

JOptionPane.showMessageDialog(null, infos, \"友情提示

birthdayTextField.setText(\"\"); birthdayTextField.requestFocus(); return;

须为15位或18位!\" };

\

JOptionPane.INFORMATION_MESSAGE);

JOptionPane.showMessageDialog(null, infos, \"友情提示

}

idCardTextField.setText(\"\"); idCardTextField.requestFocus(); return;

if (values[0].length() > 20) {

JOptionPane.showMessageDialog(null, \"密码最长不能超

过 20 个字符!\

}

Vector rowV = new Vector(); int row = table.getRowCount(); rowV.add(row + 1);

for (int i = 0; i < values.length; i++) { }

tableModel.addRow(rowV);

table.setRowSelectionInterval(row); dao.iUser(values);

JOptionPane.showMessageDialog(null, \"用户添加完成!\

rowV.add(values[i]);

\"友情提示\

passwordTextField.setText(\"\"); passwordTextField.requestFocus(); return;

友情提示\

}

//

nameTextField.setText(\"\"); manRadioButton.setSelected(true); birthdayTextField.setText(\"\"); idCardTextField.setText(\"\"); passwordTextField.setText(\"\");

JOptionPane.INFORMATION_MESSAGE);

});

subButton.setText(\"添加\"); buttonPanel.add(subButton);

final JButton delButton = new JButton();

delButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int selectedRow = table.getSelectedRow(); String name = table.getValueAt(selectedRow,

1).toString();

int i = JOptionPane.showConfirmDialog(null, \"确定要删除

用户“\" + name

+ \"”?\友情提示\

if (i == 0) {

tableModel.removeRow(selectedRow); dao.uFreezeByName(name, \"禁用\");

JOptionPane.showMessageDialog(null, \"删除用户成功!

友情提示\

JOptionPane.INFORMATION_MESSAGE);

}

}

});

delButton.setText(\"删除\"); buttonPanel.add(delButton);

final JButton exitButton = new JButton();

exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose();

}

});

exitButton.setText(\"退出\"); buttonPanel.add(exitButton);

final JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane, BorderLayout.CENTER); tableColumnV = new Vector();

String tableColumns[] = { \"序 号\姓 名\性 \

\别\"出生日期\身份证号\" };

}

}

for (int column = 0; column < tableColumns.length; column++) { }

tableValueV = new Vector(); tableValueV.addAll(dao.sUser());

tableModel = new DefaultTableModel(tableValueV, tableColumnV); table = new MTable(tableModel); if (table.getRowCount() > 0)

table.setRowSelectionInterval(0); tableColumnV.add(tableColumns[column]);

scrollPane.setViewportView(table); //

七、总结

经过这次的学习。了解了关于JAVA程序设计的一些过程,自己参与了其中的各种环节。体会良多,深感设计程序的不易。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- yrrf.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务