Java操作mysql(jdbc)实现动态的增删查改

本文介绍如何使用Java的JDBC接口连接MySQL数据库,实现员工管理系统的用户登录功能,包括注册、登录、修改密码和注销。通过创建窗口、添加组件并设置监听事件,实现与数据库的交互,对数据库进行增删查改操作。
摘要由CSDN通过智能技术生成

首先明确我们的目标:创建一个员工管理系统的用户登录界面,要求有:实现用户的注册,登录,修改密码,注销等操作。

  1. 根据分析我们首先得写一个登录窗口:
    这里写图片描述

分析步骤如下
- 首先实现一个窗口,调整位置大小,设置为可见
- 然后添加组件,图片等(合理运用好布局,流式,网格)
- 最后对按键组件添加监听事件

package day01;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.Icon;
import javax.swing.ImageIcon;
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.JTextField;

public class RegistFrame extends JFrame {
   
    JTextField txtUserName;
    JPasswordField txtPassword;
    String id;
    String pass;
    //构造器
    public RegistFrame(){
        init();
    }
    public void init(){
        //初始化窗口
        this.setTitle("登录窗口");
        this.setContentPane(createContentPane());
        this.setLocation(800, 400);
        this.setSize(400, 300);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //this.pack();
        this.setVisible(true);
    }
    public JPanel createContentPane(){
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JLabel label = new JLabel("登录界面",JLabel.CENTER);
        panel.add(BorderLayout.NORTH,label);
        panel.add(BorderLayout.CENTER,createCenterPane());

        panel.add(BorderLayout.SOUTH,createBottomPane());
        return panel;
    }
    public JPanel createCenterPane(){
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        Icon image = new ImageIcon("src/day01/sh.jpg");
        JLabel label = new JLabel(image);
        panel.add(BorderLayout.CENTER,label);
        panel.add(BorderLayout.SOUTH,createIdPwdPane());
        return panel;
    }
    public JPanel createIdPwdPane(){
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(2,3,5,5));
        panel.add(new JLabel("用  户  名:",JLabel.CENTER));
        txtUserName = new JTextField(15);
        panel.add(txtUserName);
        JButton b3 = new JButton("修改密码");
        panel.add(b3);
        panel.add(new JLabel("密        码:",JLabel.CENTER));
        txtPassword = new JPasswordField(15);
        panel.add(txtPassword);
        JButton b4 = new JButton("注销");
        panel.add(b4);
        b3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                new Siugaimima();
            }
        });
        b4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                new Zhuxiao();
            }
        });
        return panel;
    }
    public JPanel createBottomPane(){
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());
        JButton b1 = new JButton("登录");
        JButton b2 = new JButton("注册");
        panel.add(b1);
        panel.add(
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值