package log;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import custom.Custom;
import yg.YG;
public class Log extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = -1886380881308979996L;
public static String userId;
// 创建窗体并设计标题
JFrame jfrm = new JFrame("小区停车管理系统");
// 创建3个面板
// 小面板依附于大的框架
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();
// 创建3个标签
JLabel jl1 = new JLabel("欢迎使用小区停车管理系统", JLabel.CENTER);
JLabel jl2 = new JLabel("账号:");
JLabel jl3 = new JLabel("密码:");
// 创建2个文本输入框
JTextField jtf1 = new JTextField(13);
JPasswordField jtf2 = new JPasswordField(13);
// 创建2个按钮
JButton jb1 = new JButton("登录");
JButton jb2 = new JButton("取消");
// 创建2个单选按钮
JRadioButton jr1 = new JRadioButton("用户");
JRadioButton jr3 = new JRadioButton("管理员");
// 构造方法
public Log() {
jfrm.setBounds(700, 200, 400, 400);
Container contentPane = jfrm.getContentPane();
contentPane.setLayout(null);
jp1.add(jl1);
jl1.setFont(new Font("", 1, 15)); // 背景色
jl1.setForeground(Color.blue);
jp1.setLayout(new FlowLayout(FlowLayout.CENTER));
jp2.add(jl2);
jp2.add(jtf1);
jp2.setLayout(new FlowLayout(FlowLayout.CENTER));
jp3.add(jl3);
jp3.add(jtf2);
jp3.setLayout(new FlowLayout(FlowLayout.CENTER));
ButtonGroup grp = new ButtonGroup();
jr1.setBounds(285, 105, 150, 20);
jr3.setBounds(285, 133, 140, 15);
grp.add(jr1);
grp.add(jr3);
jfrm.add(jr1);
jfrm.add(jr3);
jfrm.add(jp1);
jfrm.add(jp2);
jfrm.add(jp3);
jfrm.add(jb1);
jfrm.add(jb2);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb1.setBounds(100, 200, 85, 30);
jb2.setBounds(200, 200, 85, 30);
contentPane.add(jb1);
contentPane.add(jp1);
contentPane.add(jp2);
contentPane.add(jp3);
jl1.setBounds(120, 30, 200, 40);
jp1.setBounds(40, 50, 300, 60);
jp2.setBounds(25, 100, 300, 60);
jp3.setBounds(25, 150, 300, 60);
jfrm.setVisible(true);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/* 事件监听 具体的实现方法 */
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jb1)// 进行事件源的判断 如果登录
{
if (jr1.isSelected())// 简单查询
{
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=小区停车管理系统";
String userName = "sa";
String userPwd = "1";
userId = null; // 用户
try {
Class.forName(driverName);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
Connection con = DriverManager.getConnection(dbURL, userName, userPwd);
Statement s = con.createStatement();
String r1 = "select * from 用户 where 用户账号=? and 密码=?";
PreparedStatement P = con.prepareStatement(r1);
P.setString(1, jtf1.getText());
P.setString(2, jtf2.getText());
ResultSet rs = P.executeQuery();
if (rs.next()) {
userId = rs.getString("用户账号").trim();
new YG(userId);
jfrm.setVisible(false);
}
else {
JOptionPane.showMessageDialog(null, "用户账号或密码不正确!");
}
s.close();
con.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
if (jr3.isSelected())//
{
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=小区停车管理系统";
String userName = "sa";
String userPwd = "1";
userId = null; // 管理员
try {
Class.forName(driverName);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
Connection con = DriverManager.getConnection(dbURL, userName, userPwd);
Statement s = con.createStatement();
String r1 = "select * from 管理员 where 管理员账号=? and 密码=?";
PreparedStatement P = con.prepareStatement(r1);
P.setString(1, jtf1.getText());
P.setString(2, jtf2.getText());
ResultSet rs = P.executeQuery();
if (rs.next()) {
userId = rs.getString("管理员账号").trim();
new Custom(userId);
jfrm.setVisible(false);
}
else {
JOptionPane.showMessageDialog(null, "管理员账号或密码不正确!");
}
s.close();
con.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
else if (e.getSource() == jb2) {
System.exit(0);
}
}
public static void main(String[] args) {
new Log();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
内部包含有完整的Java代码以及数据库脚本文件以及数据库源文件和完整的实验报告, 本课程提供了一系列完整的Java代码和数据库脚本文件,同时也包含了相关的数据库源文件和详实的实验报告,旨在为学生提供一个全方位的学习体验。通过本课程,学生不仅能够掌握Java编程语言和基本的数据库操作技能,还能了解到如何将二者结合起来实现有效的应用程序开发。课程涵盖了整个实验项目,每个实验都带有具体的任务要求和可行性分析,帮助学生逐步理解数据库应用的设计流程和开发过程,并培养其独立思考和问题解决的能力。让学生了解常用的开发工具和技术,进一步提高其实际开发的水平。对于缺乏实践经验的学生,本课程还提供了丰富的实例演示和案例分析,帮助他们快速掌握基本的开发技能并获得实践经验。总之,本课程是一个完整的Java数据库应用课程,旨在帮助学生掌握数据库开发的核心技能,拥有从概念到实现的全面了解和掌握。无论您是初学者还是经验丰富的Java开发者,都可以从本课程中获得帮助,并提高自己的技术水平。
资源推荐
资源详情
资源评论























收起资源包目录


























共 14 条
- 1
资源评论


猿代码i
- 粉丝: 506
- 资源: 42
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
