当前位置:首页 > 大学生社团信息管理系统
JLabel imagLabel=new JLabel(background); this.setSize(800, 600);//设置大小
this.setLocationRelativeTo(null);//放在屏幕中间 this.setResizable(false);//不可改变大小
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭属性 Container cont=this.getContentPane(); cont.setLayout(null);//自定义布局
lbTip.setFont(new Font(\黑体\lbTip.setForeground(Color.BLUE); lbTip.setBounds(0, 30, 800, 100); cont.add(lbTip);
lbUsername.setBounds(150, 200, 100, 25);
lbUsername.setFont(new Font(\宋体\txtUsername.setBounds(280, 200, 250, 28); cont.add(lbUsername); cont.add(txtUsername);
lbPassword.setBounds(150, 290, 100, 25);
lbPassword.setFont(new Font(\宋体\txtPassword.setBounds(280, 290, 250, 28); cont.add(lbPassword); cont.add(txtPassword);
btnLogin.setBounds(210, 380, 80, 25); btnCancel.setBounds(400, 380, 80, 25);
btnLogin.addActionListener(new LoginAction()); btnLogin.setFont(new Font(\宋体\btnCancel.addActionListener(new CancelAction()); btnCancel.setFont(new Font(\宋体\cont.add(btnLogin); cont.add(btnCancel);
9
}
this.getLayeredPane().add(imagLabel,newInteger(Integer.MIN_VALUE)); }
public static User getMainUser() { }
public static void setMainUser(User mainUser) { }
public static void main(String[] args) { }
new LoginFrame();
LoginFrame.mainUser = mainUser; return mainUser;
imagLabel.setBounds(0, 0, this.getWidth(), this.getHeight()); cont.add(imagLabel);
this.setVisible(true); //可见性
4.3登录模块实现过程
登录窗口设计十分简单,有一个用户名文本框,一个密码文本框,一个登录按钮和一个取消按钮组成。下面将实现介绍登录模块的实现过程。
(1)实现用户登录操作的数据表是user,首先创建与数据表对应的JaveBeen类User,该类中属性与数据表中字段一一对应,并包含了属性的get与set方法,具体代码如下:
package com.zky.www.model; public class User {//javabean
private int userId; private String username; private String password;
public User(int userId, String username, String password) {
super();
this.userId = userId;
10
}
}
this.username = username; this.password = password;
public User(String username, String password) { }
public User() { }
public int getUserId() { }
public void setUserId(int userId) { }
public String getUsername() { }
public void setUsername(String username) { }
public String getPassword() { }
public void setPassword(String password) { }
11
super();
this.username = username; this.password = password;
super();
return userId;
this.userId = userId;
return username;
this.username = username;
return password;
this.password = password;
(2)定义类UserDao,在该类中实现按用户名与密码查询用户的方法getUser(),该方法的返回值为User对象。具体代码如下:
package com.zky.www.dao; public class UserDao {
public User checkLogin(Connection conn,User user) { }
public int modifyPassword(Connection conn, User passUser) {
int flag=-1;
String sql=\try{
PreparedStatement pstmt=conn.prepareStatement(sql);
12
User resultUser=null;
String sql=\try {
PreparedStatement pstmt=conn.prepareStatement(sql); pstmt.setString(1, user.getUsername()); pstmt.setString(2,user.getPassword()); ResultSet rs=pstmt.executeQuery(); if(rs.next()){ }
resultUser=new User();
resultUser.setUserId(rs.getInt(\resultUser.setUsername(rs.getString(\resultUser.setPassword(rs.getString(\
} catch (SQLException e) { }
return resultUser;
e.printStackTrace();
共分享92篇相关文档