用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

课程管理系统

2017-12-01 作者: 云代码会员举报

[java]代码库

package com.course.UI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.course.BLL.UserDao;
import com.course.DAL.DbUtil;
import com.course.DAL.User;
import com.course.UTIL.Alert;
import com.course.UTIL.Tools;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class LoginWindow extends JFrame {

	private JPanel contentPane;
	private JTextField txt_usn;
	private JPasswordField txt_pwd;
	DbUtil dbUtil=new DbUtil();
	UserDao ud=new UserDao();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginWindow frame = new LoginWindow();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginWindow() {
		setTitle("\u7528\u6237\u767B\u5F55");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabe = new JLabel("课程管理登录系统");
		lblNewLabe.setBounds(105, 30, 126, 35);
		contentPane.add(lblNewLabe);
		
		JLabel lblNewLabel_1 = new JLabel("用户");
		lblNewLabel_1.setBounds(60, 97, 35, 24);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("密码");
		lblNewLabel_2.setBounds(60, 151, 35, 24);
		contentPane.add(lblNewLabel_2);
		
		txt_usn = new JTextField();
		txt_usn.setBounds(105, 99, 152, 22);
		contentPane.add(txt_usn);
		txt_usn.setColumns(10);
		
		JButton btn_login = new JButton(" \u767B\u5F55");
		btn_login.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String usn = txt_usn.getText().trim();
				String pwd = new String(txt_pwd.getPassword()).trim();
				if (Tools.isEmpty(usn)) {
					Alert.show("用户名不能为空");
					return;
				}
				if(Tools.isEmpty(pwd)) {
					Alert.show("密码不能为空");
					return;
				}
				User user = new User(usn,pwd);
				Connection conn = null;
				try {
					conn = dbUtil.getCon();
					if (ud.login(conn, user)!= null)
					{
						LoginWindow.this.dispose();
					new MainWindow().setVisible(true);
					}
					else
						Alert.show("用户名或密码错误!");
				}catch (Exception e) {
						e.printStackTrace();
						Alert.show("登陆失败");
					}finally {
						try {
							dbUtil.getClose(conn);
						}catch (Exception e) {
							e.printStackTrace();;
						}
					}
				
				
				}
		});
		
		btn_login.setBounds(66, 213, 74, 23);
		contentPane.add(btn_login);
		
		JButton btn_reset = new JButton(" \u91CD\u7F6E");
		btn_reset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				txt_usn.setText("");
				txt_pwd.setText("");
			}
		});
		btn_reset.setBounds(205, 213, 74, 23);
		contentPane.add(btn_reset);
		
		txt_pwd = new JPasswordField();
		txt_pwd.setBounds(105, 153, 152, 22);
		contentPane.add(txt_pwd);
	
}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...