java 用户登录_java编写用户登录
展开全部
代码发给你,如果什么都不懂的话,估计你也难以运行成功,32313133353236313431303231363533e59b9ee7ad9431333238663034而且图片也没有,要自己会改就能运行了。这些代码希望能帮到你!
数据库文件:
create database hotel_Flyer
go
use hotel_Flyer
create table userInfo(
id int primary key identity(1,1),
userName varchar(20),
password varchar(10),
realName nvarchar(20),
sex nvarchar(2),
age int,
favorite nvarchar(100),
telNum varchar(12),
email varchar(50),
address nvarchar(200)
)
go
insert into userInfo(userName,password) values('李连杰','123')
insert into userInfo(userName,password) values('成龙','123')
insert into userInfo(userName,password) values('甄子丹','123')
insert into userInfo(userName,password) values('赵文卓','123')
insert into userInfo(userName,password) values('吴京','123')
insert into userInfo(userName,password) values('周星驰','123')
insert into userInfo(userName,password) values('刘德华','123')
加载驱动类:
public class ConToSQL {
Connection con=null;
public Connection getConnection() throws Exception{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=hotel_Flyer", "sa", "sa");
return con;
}
}
连接数据库类:
public class DengluUC {
Connection con=null;
PreparedStatement stm=null;
ResultSet rs=null;
public boolean checkUser(String user,String pwd){
boolean tof=false;
try {
ConToSQL cts=new ConToSQL();
con=cts.getConnection();
stm=con.prepareStatement("select password from userInfo where userName=?");
stm.setString(1, user);
rs=stm.executeQuery();
if(rs.next()){
if(rs.getString(1).equals(pwd)){
tof= true;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} /*finally{
try {
rs.close();
stm.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
return tof;
}*/
return tof;
}
}
登录类代码:
package com.hbsoft.hotel_Flyer.login;
import com.hbsoft.hotel_Flyer.usermanagerForm.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.text.html.Option;
import com.hbsoft.hotel_Flyer.proc.Process;
import java.awt.Point;
import java.sql.*;
import com.hbsoft.hotel_Flyer.database.*;
public class Denglu {
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="61,26"
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JComboBox jComboBox = null;
private JLabel jL4 = null;
private JLabel jLabel1 = null;
private JPasswordField jPasswordField = null;
private JButton jB1 = null;
private JButton jB2 = null;
private JComboBox jComboBox1 = null;
private JLabel jLabel = null;
private JLabel jLabel2 = null;
private Connection con=null; // @jve:decl-index=0:
private Statement sts=null;
private ResultSet rs=null;
private DatabaseMetaData dmd=null;
private int rowCount=0;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
public JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame("系统登陆");
jFrame.setSize(new Dimension(854, 539));
jFrame.setLocation(new Point(100, 100));
jFrame.setContentPane(getJContentPane());
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setResizable(false);
}
return jFrame;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(3, 4, 845, 503));
jLabel2.setIcon(new ImageIcon("E:/java\uff088\uff09\u73ed\u5468\u67ab/\u7b2c\u5341\u7ec4\u5de5\u4f5c\u7ad9/hotel_Flyer/\u767b\u5f55\u80cc\u666f.jpg"));
jLabel2.setText("");
jLabel = new JLabel();
jLabel.setText("");
jLabel.setIcon(new ImageIcon(getClass().getResource("/com/hbsoft/hotel_Flyer/img/\u767b\u5f55\u80cc\u666f.jpg")));
jLabel.setBounds(new Rectangle(-1, 1, 851, 509));
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(438, 141, 363, 231));
jLabel1.setText("");
jL4 = new JLabel();
jL4.setBounds(new Rectangle(484, 341, 289, 28));
jL4.setHorizontalAlignment(SwingConstants.CENTER);
Timer t =new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e) {
Date d=new Date();
SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd hh:mm:ss");
jL4.setText(df.format(d));
}
});
t.start();
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBorder(BorderFactory.createLineBorder(Color.cyan, 2));
jContentPane.setFont(new Font("\u96b6\u4e66", Font.PLAIN, 14));
jContentPane.add(getJPanel(), null);
jContentPane.add(jL4, null);
jContentPane.add(jLabel1, null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJB1(), null);
jContentPane.add(getJB2(), null);
jContentPane.add(getJComboBox1(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel2, null);
jContentPane.add(jLabel, null);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jPanel.setBounds(new Rectangle(0, 0, 415, 0));
}
return jPanel;
}
/**
* This method initializes jB1
*
* @return javax.swing.JButton
*/
void ThisDispose(){
this.getJFrame().dispose();
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(570, 263, 201, 29));
}
return jPasswordField;
}
/**
* This method initializes jB1
*
* @return javax.swing.JButton
*/
/*void ThisdDispose(){
this.getJFrame().dispose();
}*/
private JButton getJB1() {
if (jB1 == null) {
jB1 = new JButton();
jB1.setBounds(new Rectangle(489, 313, 103, 35));
jB1.setText("登陆");
jB1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if(new DengluUC().checkUser(jComboBox1.getSelectedItem().toString(), new String(jPasswordField.getPassword()))){
//message.setText("登录成功");
//message.setForeground(new Color(255,0,0));
new Process((String)jComboBox1.getSelectedItem()).setVisible(true);
ThisDispose();
}else{
if(new String(jPasswordField.getPassword()).length()==0){
JOptionPane.showMessageDialog(null, "密码不能为空");
}else{
JOptionPane.showMessageDialog(null, "密码不正确,请重新输入");
}
}
}
});
}
return jB1;
}
/**
* This method initializes jB2
*
* @return javax.swing.JButton
*/
private JButton getJB2() {
if (jB2 == null) {
jB2 = new JButton();
jB2.setBounds(new Rectangle(642, 312, 103, 35));
jB2.setText("退出");
jB2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return jB2;
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
public void getResultSet(){
try{
con=new ConToSQL().getConnection();
sts=con.createStatement();
rs=sts.executeQuery("select * from userInfo");
}catch(Exception e){
e.printStackTrace();
}
}
public int getRowCount(){
try {
rs.last();
if (rs.isLast()) {
rowCount = rs.getRow();
}
} catch (Exception e) {
e.printStackTrace();
}
return rowCount;
}
public void closeData(){
try{
rs.close();
sts.close();
con.close();
}catch(SQLException e){
e.printStackTrace();
}
}
private JComboBox getJComboBox1() {
getResultSet();
String [] arr=new String[7];
int i=0;
try {
while (rs.next()) {
if(i
arr[i] = rs.getString(2);
i++;}
}
} catch (Exception e) {
e.printStackTrace();
}
if (jComboBox1 == null) {
jComboBox1 = new JComboBox(arr);
closeData();
jComboBox1.setBounds(new Rectangle(569, 218, 201, 29));
}
return jComboBox1;
}
public static void main(String [] args) throws Exception{
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
new Denglu().getJFrame().setVisible(true);
}
}
本回答由提问者推荐
已赞过
已踩过<
你对这个回答的评价是?
评论
收起
java 用户登录_java编写用户登录相关推荐
- java判断用户是否在某一个区域登录_Java实现QQ登录和微博第三方登录
来源:http://www.cnblogs.com/liuxianan转自公众号:Java后端 1. 前言 个人网站最近增加了评论功能,为了方便用户不用注册就可以评论,对接了 QQ 和微博这 2 大常 ...
- java实现自动登录_java实现用户自动登录
自动登录,是为了帮助用户多次使用这个网页时,不用再次输入用户名和密码就可以登录. 自动登录是指用户将用户的登录信息,人,保存到本地的文件中Cookie中. Name,value -声明时 new Co ...
- java 微信 qq 登录_java实现 微博登录、微信登录、qq登录实现代码
微信,微博,QQ,这是现在目前用的最多的手机 APP,我们做产品哪能不跟他们不沾边,对于登录,我想谁也不想要多少个帐号密码,根本记不住! 为了增加用户体验,用户能够快速的注册登录,第三方账号进行登录注 ...
- java单一登录_java实现单一登录 踢人效果
1.建一个session监听类 public class SessionListener implements HttpSessionListener{ public static HashMap s ...
- java制造病毒_java编写病毒的可行性分析
java编写病毒的可行性分析 最近心情十分郁闷,查阅一些病毒的资料消遣一下,居然发现这样的论调讲 java语言不可能编写病毒,在此特地反驳一下. 1 可执行 论调1:java需要依赖jre,无法在无j ...
- java连续输入_java – 要求用户进行多次输入
我正在尝试编写一个程序,它会一直询问用户一个整数,直到他们输入一个非整数的值,此时程序停止. 这是我到目前为止: import java.util.Scanner; import java.util. ...
- java post 登陆_java HttpPost 密码登录和提交表单的案例
记录java HttpPost 密码登录鉴权和提交表单的案例,使用的是httppost而不是HttpURLConnection httpost需要下面的依赖 org.apache.httpcompon ...
- java 图形 登录_Java图形界面——登录框
/* * 登录框 */ package com.test.swing; import java.awt.*; import javax.swing.*; public class Test1 exte ...
- java webservice用户验证_java webservice 用户验证 (服务端 + 客户端)
说明:在网上找了一堆 handler验证的东东,试验了一下,没成功. 现在换了一种方式:在 tomcat的配置文件中添加用户角色和用户信息 然后在 webservice的项目配置文件中增加对应的角色. ...
- java 存储输入_java将用户输入信息保存至txt文件
[实例简介]防止创建多个字符串对象 [实例截图] [核心代码] package com.mingrisoft; import java.awt.EventQueue; import java.awt. ...
最新文章
- 颜值绝绝子的swagger-ui
- Spring MVC + Hibernate JPA + Bootstrap 搭建的博客系统
- RNN的优秀变种: LSTM GRU
- spring配置的相关文章
- Python 默认参数值
- QT的QNetworkAccessManager类的使用
- linux下设置定时任务,linux下定时任务设置
- des加密密码补位_密码学中的数据加密标准(DES)
- firebase使用_如何开始使用Firebase Hosting
- pass 软件_怎么用电脑剪辑音乐?用什么剪辑软件好?
- 隐藏Magisk、LSPosed、Root等痕迹
- 电子标签有哪些封装方式
- Android 人脸识别,活体检测离线SDK
- 小程序支付:appid和mch_id不匹配采坑实录
- Android仿微信通讯录
- Centos7.5 升级openssh到9.0p1
- linux操作系统下 c语言编程入门
- httpsproxy2http(一个开源的反向代理服务器)
- LRU 不知道?这个生活实例一定知道吧!
- 关于学校食堂工人的调查
热门文章
- NVIDIA Jetson之OTA远程升级Jetpack
- java-net-php-python-java校园约球网站计算机毕业设计程序
- 11:Hive从0到1系列学习:函数之常用的内置函数
- webpack-theme-color-replacer 路由跳转之后,样式丢失
- 【端午安康SXY】Python正则表达式进阶用法(以批量修改Markdown英文字体为例)
- Anchor-Free系列之CornerNet: Detecting Objects as Paired Keypoints
- 怎样启动模拟器模拟鸿蒙系统,鸿蒙OS 模拟器运行
- ip地址:string和int互转方案
- 灭霸一个响指,被腰砍的电子阅读市场步入终局之战?
- 计算机网络经典面试题:在浏览器中输入URL并按下回车后会发生什么?