【实例简介】一个很基础的Java实例,实现最基础的增删改查

【实例截图】

账号:01101  密码:1234

【核心代码】

package com.sqc.view;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.border.EmptyBorder;

import com.sqc.dao.UserDao;

import com.sqc.model.User;

import com.sqc.util.DbUtil;

import com.sqc.util.StringUtil;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.BoxLayout;

import java.awt.FlowLayout;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import java.awt.Font;

import javax.swing.ImageIcon;

import javax.swing.JTextField;

import javax.swing.LayoutStyle.ComponentPlacement;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.awt.event.ActionEvent;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

public class LoginFra extends JFrame {

private JPanel contentPane;

private JTextField userName_text;

private JPasswordField password_text;

private DbUtil dbUtil=new DbUtil();

private UserDao userDao=new UserDao();

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

LoginFra frame = new LoginFra();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public LoginFra() {

setTitle("\u6854\u5B50\u9152\u5E97\u7BA1\u7406\u7CFB\u7EDF");

setResizable(false);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 557, 444);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JLabel password = new JLabel("\u5458\u5DE5\u53F7\uFF1A");

password.setFont(new Font("华文行楷", Font.PLAIN, 18));

password.setIcon(new ImageIcon(LoginFra.class.getResource("/image/head.png")));

JLabel label = new JLabel("\u5BC6 \u7801\uFF1A");

label.setFont(new Font("华文行楷", Font.PLAIN, 18));

label.setIcon(new ImageIcon(LoginFra.class.getResource("/image/password.png")));

userName_text = new JTextField();

userName_text.setColumns(10);

JButton btn_login = new JButton("\u767B \u5F55");

btn_login.setIcon(new ImageIcon(LoginFra.class.getResource("/image/accept.png")));

btn_login.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

loginActionPerformed(e);

}

});

btn_login.setFont(new Font("微软雅黑", Font.PLAIN, 18));

JButton btn_cancel = new JButton("\u6E05 \u9664");

btn_cancel.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

btn_cancelActionPerformed(e);

}

});

btn_cancel.setIcon(new ImageIcon(LoginFra.class.getResource("/image/refersh.png")));

btn_cancel.setFont(new Font("微软雅黑", Font.PLAIN, 18));

password_text = new JPasswordField();

JButton btnNewButton = new JButton("");

btnNewButton.setIcon(new ImageIcon(LoginFra.class.getResource("/image/theme.jpg")));

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(69)

.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)

.addComponent(label)

.addComponent(password))

.addGap(39)

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 148, GroupLayout.PREFERRED_SIZE)

.addComponent(userName_text, GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)

.addComponent(password_text))

.addContainerGap(127, Short.MAX_VALUE))

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(93)

.addComponent(btn_login)

.addPreferredGap(ComponentPlacement.RELATED, 79, Short.MAX_VALUE)

.addComponent(btn_cancel, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE)

.addGap(67))

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(33)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE)

.addGap(27)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(password)

.addComponent(userName_text, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))

.addGap(40)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(label)

.addComponent(password_text, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))

.addPreferredGap(ComponentPlacement.RELATED, 21, Short.MAX_VALUE)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(btn_login)

.addComponent(btn_cancel, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE))

.addGap(37))

);

contentPane.setLayout(gl_contentPane);

}

/**

* 登录事件处理

* @param e

*/

private void loginActionPerformed(ActionEvent evt) {

String userName=this.userName_text.getText();

String password=new String(this.password_text.getPassword());

if(StringUtil.isEmpty(userName)){

JOptionPane.showMessageDialog(null, "用户名不能为空!");

return;

}

if(StringUtil.isEmpty(password)){

JOptionPane.showMessageDialog(null, "密码不能为空!");

return;

}

User user=new User(userName,password);

Connection con=null;

try {

con=dbUtil.getCon();

User currentUser=userDao.login(con, user);

if(currentUser!=null){

dispose();

new MainFra().setVisible(true);

}else{

JOptionPane.showMessageDialog(null, "用户名或者密码错误!");

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

try {

dbUtil.closeCon(con);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

/**

* 重置事件处理

* @param e

*/

private void btn_cancelActionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

this.userName_text.setText("");

this.password_text.setText("");

}

}

java酒店管理系统_java酒店管理系统(源码+数据库脚本)相关推荐

  1. java计算机毕业设计-酒店疫情防控系统-源码+数据库+lw文档+系统

    java计算机毕业设计-酒店疫情防控系统-源码+数据库+lw文档+系统 java计算机毕业设计-酒店疫情防控系统-源码+数据库+lw文档+系统 本源码技术栈: 项目架构:B/S架构 开发语言:Java ...

  2. java计算机毕业设计个人交友网站源码+数据库+系统+lw文档+mybatis+运行部署

    java计算机毕业设计个人交友网站源码+数据库+系统+lw文档+mybatis+运行部署 java计算机毕业设计个人交友网站源码+数据库+系统+lw文档+mybatis+运行部署 本源码技术栈: 项目 ...

  3. java计算机毕业设计流行病调查平台源码+数据库+系统+lw文档+mybatis+运行部署

    java计算机毕业设计流行病调查平台源码+数据库+系统+lw文档+mybatis+运行部署 java计算机毕业设计流行病调查平台源码+数据库+系统+lw文档+mybatis+运行部署 本源码技术栈: ...

  4. java计算机毕业设计追星网站源码+数据库+系统+lw文档

    java计算机毕业设计追星网站源码+数据库+系统+lw文档 java计算机毕业设计追星网站源码+数据库+系统+lw文档 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 开发软件:idea ...

  5. 基于JAVA口红专卖网站计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA口红专卖网站计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA口红专卖网站计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Ja ...

  6. java计算机毕业设计家庭园艺服务平台源码+数据库+lw文档+系统

    java计算机毕业设计家庭园艺服务平台源码+数据库+lw文档+系统 java计算机毕业设计家庭园艺服务平台源码+数据库+lw文档+系统 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 开 ...

  7. 基于JAVA图书共享系统计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA图书共享系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA图书共享系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Ja ...

  8. 基于JAVA小型健身俱乐部网站计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA小型健身俱乐部网站计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA小型健身俱乐部网站计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开 ...

  9. 基于JAVA模拟考试系统计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA模拟考试系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA模拟考试系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Ja ...

  10. 基于JAVA旅游路线规划系统计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA旅游路线规划系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA旅游路线规划系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语 ...

最新文章

  1. c语言节点的作用,C语言链表(基本功能函数)
  2. 联机分析处理(OLAP)简介
  3. 如何高效的通过BP算法来训练CNN
  4. HGST:中国将成为新云端运算大国
  5. JavaScript的特殊函数
  6. 22. 括号生成 golang 图解
  7. python虚拟环境 pyenv_Python 虚拟环境 pyenv、venv(pyvenv)、virtualenv之间的区别
  8. JavaScript中sort方法的使用及原理详解
  9. 老表,教你一招啊!!!如何用python实现将csv文件快速导入数据库,建议收藏!!!
  10. galaxy s8 android pc,【三星GALAXYS8评测】DeX套件替代PC办公环境_三星 GALAXY S8_手机评测-中关村在线...
  11. 中小幼计算机等级培训,全国中小学教师教育技术水平考试考试系统使用培训0817.pptx...
  12. 计算机相关文献综述范文,计算机文献综述范文.doc
  13. ios 加速计效果实现
  14. Quartus18.0新建工程
  15. java雅虎邮件发送
  16. 决定一台计算机运行速度快慢的配件是什么,电脑运行慢换什么配件
  17. android的Activity采用透明主题
  18. UIView Animation 动画学习总结
  19. 最速降线问题-泛函极值
  20. API接口管理平台eoLinker-AMS V3.2.0

热门文章

  1. AMBER:对单个复合物进行分子动力学模拟的python包(resp计算电荷及gpu加速版本)
  2. 数据类型 - Array
  3. 北京市2009年住房建设计划
  4. 地下水运动方程的解析解(一维潜水)
  5. 修改3389远程端口的批处理文件.bat
  6. [转帖]奋斗5年 从月薪3500到700万!
  7. GeneXus创建第一个项目
  8. ASP.NET MVC 音乐商店 - 8. 使用 Ajax 更新的购物车
  9. 应用性能监测工具(APM)VS数据可观测平台
  10. 计算机设置了密码后不能打印了,win7系统共享打印机设置密码后无法连接如何解决...