DVD租赁系统
跟着网上的视频学的,还有个别地方写的不够好,主要学习dao模式,这里其中的BaseUtil类不错
DVD.java
package com.dvd.entiy; public class DVD {
private int id;
private String dname;
private int dcount;
private int status; public DVD() { } public DVD(String dname, int dcount, int status) {
super();
this.dname = dname;
this.dcount = dcount;
this.status = status;
} public DVD(int id, String dname, int dcount, int status) {
super();
this.id = id;
this.dname = dname;
this.dcount = dcount;
this.status = status;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getDname() {
return dname;
} public void setDname(String duname) {
this.dname = dname;
} public int getDcount() {
return dcount;
} public void setDcount(int dcount) {
this.dcount = dcount;
} public int getStatus() {
return status;
} public void setStatus(int status) {
this.status = status;
} }
User.java
package com.dvd.entiy; public class User {
private int id;
private String uname;
private String upass;
private int type; public User() { } public User(String uname, String upass, int type) {
super();
this.uname = uname;
this.upass = upass;
this.type = type;
} public User(int id, String uname, String upass, int type) {
super();
this.id = id;
this.uname = uname;
this.upass = upass;
this.type = type;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getUname() {
return uname;
} public void setUname(String uname) {
this.uname = uname;
} public String getUpass() {
return upass;
} public void setUpass(String upass) {
this.upass = upass;
} public int getType() {
return type;
} public void setType(int type) {
this.type = type;
} }
Record.java
package com.dvd.entiy; public class Record {
private int id;
private int uid;
private int did;
private String lendTime;
private String returnTime; public Record() { } public Record(int uid, int did, String lendTime, String returnTime) {
super();
this.uid = uid;
this.did = did;
this.lendTime = lendTime;
this.returnTime = returnTime;
} public Record(int id, int uid, int did, String lendTime, String returnTime) {
super();
this.id = id;
this.uid = uid;
this.did = did;
this.lendTime = lendTime;
this.returnTime = returnTime;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public int getUid() {
return uid;
} public void setUid(int uid) {
this.uid = uid;
} public int getDid() {
return did;
} public void setDid(int did) {
this.did = did;
} public String getLendTime() {
return lendTime;
} public void setLendTime(String lendTime) {
this.lendTime = lendTime;
} public String getReturnTime() {
return returnTime;
} public void setReturnTime(String returnTime) {
this.returnTime = returnTime;
} }
Record2.java
package com.dvd.entiy; public class Record2 {
private int id;// 记录id
private int did;// 影碟id
private String uname;// 用户名
private String dname;// 影碟名字
private String lendTime;// 借出时间
private String returnTime;// 归还时间 public Record2() { } public Record2(String uname, String dname, String lendTime, String returnTime) {
super();
this.uname = uname;
this.dname = dname;
this.lendTime = lendTime;
this.returnTime = returnTime;
} public Record2(int id, String uname, String dname, String lendTime, String returnTime) {
super();
this.id = id;
this.uname = uname;
this.dname = dname;
this.lendTime = lendTime;
this.returnTime = returnTime;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public int getDid() {
return did;
} public void setDid(int did) {
this.did = did;
} public String getUname() {
return uname;
} public void setUname(String uname) {
this.uname = uname;
} public String getDname() {
return dname;
} public void setDname(String dname) {
this.dname = dname;
} public String getLendTime() {
return lendTime;
} public void setLendTime(String lendTime) {
this.lendTime = lendTime;
} public String getReturnTime() {
return returnTime;
} public void setReturnTime(String returnTime) {
this.returnTime = returnTime;
} }
DVDDao.java
package com.dvd.dao; import java.util.List; import com.dvd.entiy.DVD; public interface DVDDao {
public boolean saveDVD(DVD dvd);// 添加DVD public boolean updateDVD(DVD dvd);// 更新DVD public boolean delDVD(int did);// 删除指定的DVD public List<DVD> queryDVDs();// 查询所有的DVD public List<DVD> queryDVDByName(String name);// 查找指定名字的DVD public List<DVD> querySortByLimit(int index, int number);// 查找指定起始位,指定个数的DVD public DVD queryDVDById(int did);// 根据dvd编号来查询DVD public List<DVD> queryDVDByStatus(int status);// 根据状态查询 DVD }
RecordDao.java
package com.dvd.dao; import java.util.List; import com.dvd.entiy.Record;
import com.dvd.entiy.Record2; public interface RecordDao {
public Record queryRecordById(int rid);// 查看指定id的DVD借还记录 public boolean saveRecord(Record record);// 保存record记录 public boolean updateRecord(Record record);// 更新Record记录 public List<Record2> queryAllRecord();// 查询所有的DVD借还记录 public List<Record2> queryRecordByUname(String uname);// 查看指定用户的dvd借还记录 public List<Record2> queryRecordByDname(String dname);// 查看指定dvd的借还记录 public List<Record2> queryUserRecordByReturnTime(boolean flag, String uname);// 查看用户归还
// 记录(已归还
// ,未归还)
}
UserDao.java
package com.dvd.dao; import com.dvd.entiy.User; public interface UserDao {
public boolean saveUser(User user);// 添加用户 public boolean delUser(int id);// 删除用户 public boolean updateUser(User user);// 更新用户 public User queryUser(User user);// 查询用户
}
BaseDao.java
package com.dvd.dao.impl; import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; public class BaseDao {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost:3306/dvddb"; /**
* 与数据库建立连接
*
* @return 数据库连接对象
*/
public Connection getConn() {
Connection conn = null;
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(URL, "root", "123456");
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return conn;
} /**
* 释放相应的资源
*
* @param rs
* @param pstmt
* @param conn
*/
public void closeAll(ResultSet rs, PreparedStatement pstmt, Connection conn) {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
} /**
* 此方法可以完成增删改查
*
* @param sql
* @param params
* @return
*/
public boolean operUpdate(String sql, List<Object> params) {
int res = 0;// 影响的行数
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = getConn();
pstmt = conn.prepareStatement(sql);// 装在sql语句
if (params != null) {
// 假如有?在执行之前把?点位符替换掉
for (int i = 0; i < params.size(); i++) {
pstmt.setObject(i + 1, params.get(i));
}
}
res = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} finally {
closeAll(rs, pstmt, conn);
}
return res > 0 ? true : false;
} /**
* 使用泛型方法和反射机制进行封装
*
* @param sql
* @param params
* @param cls
* @return
* @throws IllegalAccessException
* @throws InstantiationException
* @throws SecurityException
* @throws NoSuchFieldException
*/ public <T> List<T> operQuery(String sql, List<Object> params, Class<T> cls)
throws InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<T> data = new ArrayList<T>();
try {
conn = getConn();
pstmt = conn.prepareStatement(sql);// 装在sql语句
if (params != null) {
// 假如有?在执行之前把?点位符替换掉
for (int i = 0; i < params.size(); i++) {
pstmt.setObject(i + 1, params.get(i));
}
}
rs = pstmt.executeQuery();
// 把查询出来的记录封装成对应 的实体类对象
ResultSetMetaData rsd = rs.getMetaData();// 得到记录集元数据对象
// 通过此对象可以得到表的结构 ,列名,列的个数 ,列的数据类型
while (rs.next()) {
T m = cls.newInstance();
for (int i = 0; i < rsd.getColumnCount(); i++) {
String col_name = rsd.getColumnName(i + 1);// 获得列名
Object value = rs.getObject(col_name);// 获得对应的值
Field field = cls.getDeclaredField(col_name);
field.setAccessible(true);// 给私有属性设置可访问权
field.set(m, value);// 给对象私有属性赋值 }
data.add(m);
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} finally {
closeAll(rs, pstmt, conn);
}
return data;
}
}
DVDDaoImpl.java
package com.dvd.dao.impl; import java.util.ArrayList;
import java.util.List; import com.dvd.dao.DVDDao;
import com.dvd.entiy.DVD; public class DVDDaoImpl extends BaseDao implements DVDDao { @Override
public boolean saveDVD(DVD dvd) {
String sql = "insert into dvds(dname,dcount,status) values(?,?,?)";
List<Object> params = new ArrayList<Object>();
params.add(dvd.getDname());
params.add(dvd.getDcount());
params.add(dvd.getStatus());
return this.operUpdate(sql, params); } @Override
public boolean updateDVD(DVD dvd) {
String sql = "update dvds set dname=?,dcount=?,status=? where id=?";
List<Object> params = new ArrayList<Object>();
params.add(dvd.getDname());
params.add(dvd.getDcount());
params.add(dvd.getStatus());
params.add(dvd.getId());
return this.operUpdate(sql, params);
} @Override
public boolean delDVD(int did) {
String sql = "delete from dvds where id=?";
List<Object> params = new ArrayList<Object>();
params.add(did);
return this.operUpdate(sql, params);
} @Override
public List<DVD> queryDVDs() {
String sql = "select id,dname,dcount,status from dvds";
List<DVD> dList = null;
try {
dList = this.operQuery(sql, null, DVD.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return dList;
} @Override
public List<DVD> queryDVDByName(String dname) {
String sql = "select id,dname,dcount,status from dvds where dname=?";
List<DVD> dList = null;
List<Object> params = new ArrayList<Object>();
params.add(dname);
try {
dList = this.operQuery(sql, params, DVD.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return dList;
} /**
* 查询热门dvd就是借出次数前五位的dvd
*
* @param index
* @param number
* @return
*/
@Override
public List<DVD> querySortByLimit(int index, int number) {
String sql = "select id,dname,dcount,status from dvds order by dcount desc limit" + index + "," + number;
List<DVD> dList = null;
try {
dList = this.operQuery(sql, null, DVD.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return dList;
} @Override
public DVD queryDVDById(int did) {
String sql = "select id,dname,dcount,status from dvds where id=?";
List<DVD> dList = null;
List<Object> params = new ArrayList<Object>();
params.add(did);
try {
dList = this.operQuery(sql, params, DVD.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
if (dList.size() > 0) {
return dList.get(0);
}
return null;
} @Override
public List<DVD> queryDVDByStatus(int status) {
String sql = "select id,dname,dcount,status from dvds where status=?";
List<DVD> dList = null;
List<Object> params = new ArrayList<Object>();
params.add(status);
try {
dList = this.operQuery(sql, params, DVD.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return dList;
} }
RecordDaoImp.java
package com.dvd.dao.impl; import java.util.ArrayList;
import java.util.List; import com.dvd.dao.RecordDao;
import com.dvd.entiy.Record;
import com.dvd.entiy.Record2; public class RecordDaoImpl extends BaseDao implements RecordDao { @Override
public Record queryRecordById(int rid) {
List<Record> rList = null;
String sql = "select id,uid,did,lendTime,returnTime from records where did=? order by id desc";
List<Object> params = new ArrayList<Object>();
params.add(rid);
try {
rList = this.operQuery(sql, params, Record.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
if (rList.size() > 0) {
return rList.get(0);
}
return null;
} @Override
public boolean saveRecord(Record record) {
String sql = "insert into records(uid,did,lendTime,returnTime) values(?,?,?,?)";
List<Object> params = new ArrayList<Object>();
params.add(record.getUid());
params.add(record.getDid());
params.add(record.getLendTime());
params.add(record.getReturnTime()); return this.operUpdate(sql, params);
} @Override
public boolean updateRecord(Record record) {
String sql = "update records set uid=?,did=?,lendTime=?,returnTime=? where id=?";
List<Object> params = new ArrayList<Object>();
params.add(record.getUid());
params.add(record.getDid());
params.add(record.getLendTime());
params.add(record.getReturnTime());
params.add(record.getId());
return this.operUpdate(sql, params);
} @Override
public List<Record2> queryAllRecord() {
List<Record2> data = null;
String sql = "select r.id,d.id as did,u.uname,d.dname,r.lentTime,r.returnTime from users u,dvds d,records r where u.id=r.uid and d.id =r.did";
try {
data = this.operQuery(sql, null, Record2.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return data;
} @Override
public List<Record2> queryRecordByUname(String uname) {
List<Record2> data = null;
String sql = "select r.id,d.id as did,u.uname,d.dname,r.lendTime,r.returnTime from"
+ " users u,dvds d,records r where u.id=r.uid and d.id =r.did and uname=?";
List<Object> params = new ArrayList<Object>();
params.add(uname);
try {
data = this.operQuery(sql, params, Record2.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return data;
} @Override
public List<Record2> queryRecordByDname(String dname) {
List<Record2> data = null;
String sql = "select r.id,d.id as did,u.uname,d.dname,r.lendTime,r.returnTime from users u,"
+ "dvds d,records r where u.id=r.uid and d.id =r.did and dname=?";
List<Object> params = new ArrayList<Object>();
params.add(dname);
try {
data = this.operQuery(sql, params, Record2.class);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return data;
} /**
* // 查看用户归还记录(已归还 ,未归还)
*/
@Override
public List<Record2> queryUserRecordByReturnTime(boolean flag, String uname) {
List<Record2> rList = null;
String sql = null;
if (flag) {
sql = "select r.id,d.id as did,u.uname,d.dname,r.lentTime,r.returnTime from "
+ "uses u,dvds d,records r where u.id=r.uid and d.id =r.did and returnTime is not null and uname=?";
} else {
sql = "select r.id,d.id as did,u.uname,d.dname,r.lentTime,r.returnTime from "
+ "uses u,dvds d,records r where u.id=r.uid and d.id =r.did and returnTime is null and uname=?";
}
List<Object> params = new ArrayList<Object>();
params.add(uname);
try {
rList = this.operQuery(sql, params, Record2.class);
} catch (Exception e) {
e.printStackTrace();
}
return rList;
} }
UserDaoImpl.java
package com.dvd.dao.impl; import java.util.ArrayList;
import java.util.List; import com.dvd.dao.UserDao;
import com.dvd.entiy.User; public class UserDaoImpl extends BaseDao implements UserDao { @Override
public boolean saveUser(User user) {
String sql = "insert into users(uname,upass,type) values(?,?,?)";
List<Object> params = new ArrayList<Object>();
params.add(user.getUname());
params.add(user.getUpass());
params.add(user.getType());
return this.operUpdate(sql, params);
} @Override
public boolean delUser(int id) {
String sql = "delete from users where id=?";
List<Object> params = new ArrayList<Object>();
params.add(id);
return this.operUpdate(sql, params);
} @Override
public boolean updateUser(User user) {
String sql = "updata users set uname=?,upass=?,type=? where id=?";
List<Object> params = new ArrayList<Object>();
params.add(user.getUname());
params.add(user.getUpass());
params.add(user.getType());
params.add(user.getId());
return this.operUpdate(sql, params);
} @Override
public User queryUser(User user) {
List<User> uList = null;
String sql = "select id,uname,upass,type from users where uname=? and upass=? and type=?";
List<Object> params = new ArrayList<Object>();
params.add(user.getUname());
params.add(user.getUpass());
params.add(user.getType());
try {
uList = this.operQuery(sql, params, User.class);
} catch (Exception e) {
} if (uList.size() > 0) {
return uList.get(0);
}
return null;
} }
DVDBiz.java
package com.dvd.biz; import java.util.List; import com.dvd.entiy.DVD; public interface DVDBiz {
public boolean addDVD(DVD dvd);// 添加dvd public boolean delDVD(int did);// 删除dvd public boolean modifyDVD(DVD dvd);// 修改dvd public List<DVD> queryAllDVDs();// 查询所有的dvd信息 public List<DVD> ranking_top_five();// 查看前5张最爱欢迎的dvd(热门dvd) public List<DVD> queryDVDByName(String dname);// 根据DVD的名字来查询 public DVD queryDVDById(int did);// 根据id来查询 DVD public int lendDVD(int did, int uid);// 按dvd编号和用户编号来租DVD public int returnDVD(int rid);// 还DVD的功能 public List<DVD> canLendDVD();// 可借DVD public List<DVD> hasLendedDvD();// 不可DVD }
RecordBiz.java
package com.dvd.biz; import java.util.List; import com.dvd.entiy.Record2; public interface RecordBiz {
public List<Record2> queryUserRecords(String uname);// 查看指定用户的租赁记录 public List<Record2> queryDVDRecords(String dname);// 查看指定DVD的租赁记录 public List<Record2> queryHasReturnRecords(String uname);// 查看指定用户已归还 的记录 public List<Record2> queryNoReturnRecords(String uname);// 查看指定用户未归还 的记录 public List<Record2> queryAllRecords();// 查看所有的记录
}
UserBiz.java
package com.dvd.biz; import com.dvd.entiy.User; public interface UserBiz {
// 用户登录,返回的就是登录用户的信息(对象)
public User login(User user); // 注册用户
public int registerUser(User user);
}
DVDBizImpl.java
package com.dvd.biz.Impl; import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import com.dvd.biz.DVDBiz;
import com.dvd.dao.DVDDao;
import com.dvd.dao.RecordDao;
import com.dvd.dao.impl.DVDDaoImpl;
import com.dvd.dao.impl.RecordDaoImpl;
import com.dvd.entiy.DVD;
import com.dvd.entiy.Record; public class DVDBizImpl implements DVDBiz {
private DVDDao dvdDao = null;
private RecordDao recordDao = null; public DVDBizImpl() {
dvdDao = new DVDDaoImpl();
recordDao = new RecordDaoImpl();
} @Override
public boolean addDVD(DVD dvd) { return dvdDao.saveDVD(dvd);
} @Override
public boolean delDVD(int did) { return dvdDao.delDVD(did);
} @Override
public boolean modifyDVD(DVD dvd) {
return dvdDao.updateDVD(dvd);
} @Override
public List<DVD> queryAllDVDs() {
return dvdDao.queryDVDs();
} @Override
public List<DVD> ranking_top_five() {
return dvdDao.querySortByLimit(0, 5);
} @Override
public List<DVD> queryDVDByName(String dname) { return dvdDao.queryDVDByName(dname);
} @Override
public DVD queryDVDById(int did) {
return dvdDao.queryDVDById(did);
} @Override
public int lendDVD(int did, int uid) {
DVD dvd = dvdDao.queryDVDById(did);// 查询
if (dvd == null) {
return 0;// 没有找到要借的dvd
} else {
if (dvd.getStatus() == 0) {
return 1;// 不可借。已经借出
} else { dvd.setStatus(0);// 更新状态代表已经借出
dvd.setDcount(dvd.getDcount() + 1);
// System.out.println(dvd.getId());
//// System.out.println(dvd.getDname());
// System.out.println(dvd.getDcount());
// System.out.println(dvd.getStatus());
boolean flag1 = dvdDao.updateDVD(dvd);// 更新DVD
// System.out.println("更新dvdflag1=" + flag1);
Record record = new Record(uid, did, new SimpleDateFormat("yyyy-MM-dd").format(new Date()), null);
boolean flag2 = recordDao.saveRecord(record);// 插入租赁记录;
// System.out.println("更新插入租赁记录;flag2=" + flag2);
if (flag1 && flag2) {
return 2;// 借出成功
} else {
// dvd.setStatus(1);
// dvdDao.updateDVD(dvd);
return 3;// 借出失败
}
}
}
} @Override
public int returnDVD(int rid) {
Record record = recordDao.queryRecordById(rid);
// System.out.println(record);
if (record == null) {
return 1;// 输入不正确
} else if (record.getReturnTime() != null) { return 2;// dvd已经归还
} else {
record.setReturnTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
boolean flag1 = recordDao.updateRecord(record);// 更新记录
// System.out.println("更新flag= " + flag1);
DVD dvd = dvdDao.queryDVDById(record.getDid());// 打到对应的dvd
dvd.setStatus(1);// 可借状态
boolean flag2 = dvdDao.updateDVD(dvd);
// System.out.println("更新flag2= " + flag2);
if (flag1 && flag2) {
return 3;// 归还成功
} else {
dvd.setStatus(0);// 未还状态
dvdDao.updateDVD(dvd);
return 4;// 归还失败
}
}
} @Override
public List<DVD> canLendDVD() {
return dvdDao.queryDVDByStatus(1);
} @Override
public List<DVD> hasLendedDvD() {
return dvdDao.queryDVDByStatus(0);
} }
RecordBizImpl.java
package com.dvd.biz.Impl; import java.util.List; import com.dvd.biz.RecordBiz;
import com.dvd.dao.RecordDao;
import com.dvd.dao.impl.RecordDaoImpl;
import com.dvd.entiy.Record2; public class RecordBizImpl implements RecordBiz {
private RecordDao recordDao = null; public RecordBizImpl() {
recordDao = new RecordDaoImpl();
} @Override
public List<Record2> queryUserRecords(String uname) {
return recordDao.queryRecordByUname(uname);
} @Override
public List<Record2> queryDVDRecords(String dname) {
return recordDao.queryRecordByDname(dname);
} @Override
public List<Record2> queryHasReturnRecords(String uname) {
return recordDao.queryUserRecordByReturnTime(true, uname);
} @Override
public List<Record2> queryNoReturnRecords(String uname) {
// TODO 自动生成的方法存根
return recordDao.queryUserRecordByReturnTime(false, uname);
} @Override
public List<Record2> queryAllRecords() {
// TODO 自动生成的方法存根
return recordDao.queryAllRecord();
} }
UserBizImpl.java
package com.dvd.biz.Impl; import com.dvd.biz.UserBiz;
import com.dvd.dao.UserDao;
import com.dvd.dao.impl.UserDaoImpl;
import com.dvd.entiy.User; public class UserBizImpl implements UserBiz {
private UserDao userDao = null; public UserBizImpl() {
userDao = new UserDaoImpl();
} @Override
public User login(User user) {
return userDao.queryUser(user);
} @Override
public int registerUser(User user) {
if (userDao.queryUser(user) != null) {
return 1;// 此用户名已经存在
} else {
boolean res = userDao.saveUser(user);
if (res) {
return 2;// 注册成功
} else {
return 3;// 注册失败
}
}
} }
AdminDVDOperatorView.java
package com.dvd.view; import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List; import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel; import com.dvd.Util.DVDUtil;
import com.dvd.biz.DVDBiz;
import com.dvd.biz.Impl.DVDBizImpl;
import com.dvd.entiy.DVD; public class AdminDVDOperatorView extends JInternalFrame { private static final long serialVersionUID = -3558209667843105955L;
private DVDBiz dvdBiz = null;
private List<DVD> dvdList = null;
private DVDInfoTableModel infoTableModel = null; private JPanel paneltable = null;
private JScrollPane jScrollPanetable = null;// 用来保存Jtable的一个面板
private JTable table = null;// 声明JTable
private JPanel panelmanage = null;
private JPanel manage = null;// 声明信息 private JPanel panelbutton = null;// 按钮面板
private JTextField tf_search = null;
private JButton btn_search = null;
private JButton btn_add = null;
private JButton btn_updata = null;
private JButton btn_del = null;
private JButton btn_exit = null;
private JComboBox<String> cb_type = null;
private JLabel lb_type = null; private JLabel lb_name = null;
private JLabel lb_count = null;
private JLabel lb_status = null;
private JTextField tf_name = null;
private JTextField tf_count = null;
private JComboBox<String> cb_status = null; public AdminDVDOperatorView() {
dvdBiz = new DVDBizImpl();
init();
registerListener();
} private void init() {
this.setTitle("DVD租赁记录查询");
this.setSize(525, 450);
this.setIconifiable(true);// 窗体可最小化
this.setClosable(true);// 窗体可被关闭
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
dvdList = new ArrayList<DVD>(); lb_name = new JLabel("DVD名字", JLabel.CENTER);
lb_count = new JLabel("借出次数", JLabel.CENTER);
lb_status = new JLabel("DVD状态", JLabel.CENTER);
tf_name = new JTextField(8);
tf_count = new JTextField(8);
cb_status = new JComboBox<String>(new String[] { "已借", "可借" });
paneltable = new JPanel(new BorderLayout());
panelmanage = new JPanel();
manage = new JPanel(); table = new JTable(); // 让JTable绑定数据模型呈现数据 refreshTable(dvdList); manage.add(lb_name);
manage.add(tf_name);
manage.add(lb_count);
manage.add(tf_count);
manage.add(lb_status);
manage.add(cb_status); jScrollPanetable = new JScrollPane();// 创建面板
// 给面板设置边框
paneltable
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "DVD记录查询 "));
jScrollPanetable.setViewportView(table);
paneltable.add(jScrollPanetable);
panelmanage.add(manage);
paneltable.add(panelmanage, BorderLayout.SOUTH);
this.add(paneltable, BorderLayout.CENTER);
// 给面板设置边框
panelmanage.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null))); panelbutton = new JPanel(new GridLayout(9, 1, 5, 10));
// 给面板设置边框
panelbutton.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "查询条件"));
this.add(panelbutton, BorderLayout.EAST);
lb_type = new JLabel("查询类型");
panelbutton.add(lb_type);
cb_type = new JComboBox<String>(new String[] { "所有DVD", "DVD编号", "DVD名字" });
panelbutton.add(cb_type); tf_search = new JTextField();
panelbutton.add(tf_search); btn_search = new JButton("查询");
panelbutton.add(btn_search);
tf_search.setEditable(false);// 默认不可用 btn_add = new JButton("添加DVD");
panelbutton.add(btn_add); btn_updata = new JButton("更新DVD");
panelbutton.add(btn_updata);
btn_updata.setEnabled(false);// 默认不可用 btn_del = new JButton("删除DVD");
panelbutton.add(btn_del);
btn_del.setEnabled(false);// 默认不可用 panelbutton.add(new JLabel());
this.getRootPane().setDefaultButton(btn_search);// 设置默认获取的焦点 btn_exit = new JButton("退出窗口");
panelbutton.add(btn_exit); this.setVisible(true);
} private void registerListener() { btn_exit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int flag = JOptionPane.showInternalConfirmDialog(AdminDVDOperatorView.this, "是否确定退出?", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
AdminDVDOperatorView.this.dispose();
}
}
}); btn_del.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();// 取得选中的那行
int did = (Integer) table.getValueAt(row, 0);
int flag = JOptionPane.showInternalConfirmDialog(AdminDVDOperatorView.this, "是否确定删除DVD?", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
boolean res = dvdBiz.delDVD(did);
if (res) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "删除成功!");
return;
} else {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "删除失败,请联系管理员!!");
return;
}
}
}
}); btn_updata.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
String dname = tf_name.getText().trim();
String dcount = tf_count.getText().trim();
int status = cb_status.getSelectedIndex();
if (dname.equals("")) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "DVD名字不能为空");
return;
} else if (dcount.equals("")) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "借出次数不能为空");
return;
}
if (!DVDUtil.isNumber(dcount)) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "DVD借出次数只能是数字");
return;
}
int flag = JOptionPane.showInternalConfirmDialog(AdminDVDOperatorView.this, "是否确定更新DVD?", "确认信息",
JOptionPane.YES_NO_OPTION); if (flag == JOptionPane.YES_OPTION) {
int row = table.getSelectedRow();
boolean res = dvdBiz
.modifyDVD(new DVD((Integer) table.getValueAt(row, 0), dname, new Integer(dcount), status));
System.out.println(res);
if (res) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "更新成功!");
return;
} else {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "更新失败,请联系管理员!");
return;
}
}
}
}); table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
/// 假设选中一行,更新删除按钮可用
if (table.getSelectedRow() != -1) {
btn_del.setEnabled(true);
btn_updata.setEnabled(true); }
int row = table.getSelectedRow();// 得到你所选中那行的下标
String dname = table.getValueAt(row, 1).toString();
String dcount = table.getValueAt(row, 2).toString();
String status = table.getValueAt(row, 3).toString();
tf_name.setText(dname);
tf_count.setText(dcount);
cb_status.setSelectedItem(status);
}
}); cb_type.addItemListener(new ItemListener() { @Override
public void itemStateChanged(ItemEvent e) {
String item = e.getItem().toString();
tf_search.setText("");
if (item.equals("所有DVD")) {
tf_search.setEditable(false);
} else {
tf_search.setEditable(true);
}
}
}); btn_add.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
String dname = tf_name.getText().trim();
String dcount = tf_count.getText().trim();
int status = cb_status.getSelectedIndex();// 0代表已经借出,1代表可借
if (dname.equals("")) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "DVD名字不能为空");
return;
} else if (dcount.equals("")) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "借出次数不能为空");
return;
}
if (!DVDUtil.isNumber(dcount)) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "DVD借出次数只能是数字");
return;
}
int flag = JOptionPane.showInternalConfirmDialog(AdminDVDOperatorView.this, "是否确定添加DVD?", "确认信息",
JOptionPane.YES_NO_OPTION); if (flag == JOptionPane.YES_OPTION) {
boolean res = dvdBiz.addDVD(new DVD(dname, new Integer(dcount), status));
if (res) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "添加成功!");
return;
} else {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "添加失败,请联系管理员!!");
return;
}
}
}
}); btn_search.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { int index = cb_type.getSelectedIndex();
String content = tf_search.getText().trim();
if (index != 0 && content.equals("")) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "查询的内容不能为空");
return;
}
// 先清除数据 ,防止数据 的累加
if (dvdList != null) {
dvdList.clear();
}
if (index == 0) {
dvdList = dvdBiz.queryAllDVDs();
} else if (index == 1) {
tf_search.setEnabled(true);// 输入框可用
if (DVDUtil.isNumber(content)) {
DVD dvd = dvdBiz.queryDVDById(Integer.parseInt(content));
if (dvd != null) {
dvdList.add(dvd);
}
} else {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "输入的编号只能是数字");
return;
}
} else {
dvdList = dvdBiz.queryDVDByName(content);
}
refreshTable(dvdList);
btn_del.setEnabled(false);
btn_updata.setEnabled(false);
if (dvdList.size() == 0) {
JOptionPane.showInternalMessageDialog(AdminDVDOperatorView.this, "没有你要查询的记录!");
return;
}
}
});
} private class DVDInfoTableModel implements TableModel {
private List<DVD> dvdsList = null; private DVDInfoTableModel(List<DVD> dvdList) {
this.dvdsList = dvdList;
} @Override
public void addTableModelListener(TableModelListener l) { } // JTable 列的数据类型
public Class<?> getColumnClass(int columnIndex) { return String.class;
} // JTable数据 的列数
public int getColumnCount() { return 4;
} // 设置 JTable数据 的列名
public String getColumnName(int columnIndex) {
if (columnIndex == 0) {
return "影碟ID";
} else if (columnIndex == 1) {
return "影碟名字";
} else if (columnIndex == 2) {
return "影碟借出次数";
} else if (columnIndex == 3) {
return "影碟状态";
} else {
return "出错";
}
} // JTable显示 的行数
public int getRowCount() { return dvdsList.size();
} // 获取JTable中指定行指定单元格的数据
public Object getValueAt(int rowIndex, int columnIndex) {
DVD dvd = dvdsList.get(rowIndex);
if (columnIndex == 0) {
return dvd.getId();
} else if (columnIndex == 1) {
return dvd.getDname();
} else if (columnIndex == 2) {
return dvd.getDcount();
} else if (columnIndex == 3) {
return "" + (dvd.getStatus() == 1 ? "可借" : "已借");
} else {
return "出错";
}
} // 设置单元格是否可以编辑
public boolean isCellEditable(int rowIndex, int columnIndex) { return false;
} @Override
public void removeTableModelListener(TableModelListener l) { } @Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } } // 刷新Jtable并显示数据
private void refreshTable(List<DVD> dvdList) {
infoTableModel = new DVDInfoTableModel(dvdList);
table.setModel(infoTableModel);
}
}
AdminMainView.java
package com.dvd.view; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import com.dvd.entiy.User; public class AdminMainView extends JFrame {
private static final long serialVersionUID = -7828161836358813128L; private JPanel panel_main = null;
private JPanel panel_wel = null;
private JDesktopPane desktopPane = null;
private JPanel panel_btn = null; private JButton btn_query_rent_dvd = null;
private JButton btn_dvd_record = null;
private JButton btn_exit = null; private JLabel lb_welcome = null;
private JLabel desk_img = null;
private User user = null; public AdminMainView(User user) {
this.user = user;
init();
registerListener(); } private void init() { panel_main = new JPanel(new BorderLayout());
panel_wel = new JPanel();
desktopPane = new JDesktopPane();
panel_btn = new JPanel(new GridLayout(7, 1, 0, 35)); btn_query_rent_dvd = new JButton("管理员DVD查询操作");
btn_dvd_record = new JButton("DVD租赁记录查询");
btn_exit = new JButton("退出窗口");
/*
* 快捷功能区
*/ panel_btn.setBorder(BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "快捷功能区"));
panel_btn.add(new JLabel());
panel_btn.add(new JLabel());
panel_btn.add(btn_query_rent_dvd);
panel_btn.add(btn_dvd_record);
panel_btn.add(btn_exit);
panel_btn.add(new JLabel());
panel_btn.add(new JLabel()); /*
* 欢迎区
*/
lb_welcome = new JLabel("欢 迎 " + user.getUname() + " 使 用 影 碟 租 赁 管 理 系 统");
lb_welcome.setFont(new Font("宋体", Font.BOLD, 23));
lb_welcome.setForeground(Color.BLUE);
panel_wel.add(lb_welcome);
EventQueue.invokeLater(new Runnable() { @Override
public void run() {
new Thread(new DynaminThread()).start(); }
});
/*
* 主面板
*/
ImageIcon image = new ImageIcon("src/images/main.png");
desk_img = new JLabel(image);
desk_img.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
desktopPane.add(desk_img, new Integer(Integer.MIN_VALUE)); panel_main.add(panel_wel, BorderLayout.NORTH);
panel_main.add(panel_btn, BorderLayout.EAST);
panel_main.add(desktopPane, BorderLayout.CENTER); this.getContentPane().add(panel_main);
this.setTitle("管理员操作主面板");
// this.setSize(1000, 650);
this.pack();
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
} private void registerListener() { /*
* 管理员DVD查询操作
*/
btn_query_rent_dvd.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
AdminDVDOperatorView qdv = new AdminDVDOperatorView();
desktopPane.add(qdv);// 把指定的视图添加到时桌面容器中去
qdv.toFront();// 视图显示 的前面 }
}); /*
* DVD租赁记录查询
*/
btn_dvd_record.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
AdminQueryDVDRecord qdv = new AdminQueryDVDRecord();
desktopPane.add(qdv);// 把指定的视图添加到时桌面容器中去
qdv.toFront();// 视图显示 的前面 }
}); /*
* 退出窗口
*/
btn_exit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int flag = JOptionPane.showConfirmDialog(AdminMainView.this, "是否确定退出窗口", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
System.exit(0);// 关闭窗体,并释放全部资源。
// AdminMainView.this.dispose();// 关闭窗体,释放一部分资源。
}
}
}); } /**
* 这是一个线程类,专门用来进行对欢迎Label标签进行移动
*
* @author LZC
*
*/
private class DynaminThread implements Runnable { @Override
public void run() {
while (true) {
for (int i = 780; i > -650; i--) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
lb_welcome.setLocation(i, 5);
}
} }
} }
AdminQueryDVDRecord.java
package com.dvd.view; import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List; import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel; import com.dvd.biz.RecordBiz;
import com.dvd.biz.Impl.RecordBizImpl;
import com.dvd.entiy.Record2; public class AdminQueryDVDRecord extends JInternalFrame { private static final long serialVersionUID = -3558209667843105955L;
private JScrollPane jScrollPanetable = null;// 用来保存Jtable的一个面板
private JTable table = null;// 声明JTable private JPanel panelbutton = null;// 按钮面板
private JTextField tf_insert = null;
private JButton btn_search = null;
// private JButton btn_rent = null;
private JButton btn_exit = null;
private JComboBox<String> cb_type = null;
private JLabel lb_type = null; private List<Record2> record2List = null;
private DVDInfoTableModel infoTableModel = null;
RecordBiz recordBiz = null; public AdminQueryDVDRecord() { init();
registerLister(); } private void init() {
this.setTitle("DVD租赁记录查询");
this.setSize(525, 450);
this.setIconifiable(true);// 窗体可最小化
this.setClosable(true);// 窗体可被关闭
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLayout(new BorderLayout()); recordBiz = new RecordBizImpl(); record2List = new ArrayList<Record2>();
table = new JTable();
jScrollPanetable = new JScrollPane();// 创建面板
// 给面板设置边框
jScrollPanetable
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "DVD记录查询 "));
jScrollPanetable.setViewportView(table);
this.add(jScrollPanetable, BorderLayout.CENTER); panelbutton = new JPanel(new GridLayout(9, 1, 10, 10));
// 给面板设置边框
panelbutton.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "查询条件"));
this.add(panelbutton, BorderLayout.EAST);
refreshTable(record2List);
lb_type = new JLabel("查询类型");
panelbutton.add(lb_type);
cb_type = new JComboBox<String>(new String[] { "指定用户租赁记录", "指定DVD租赁记录" });
panelbutton.add(cb_type); tf_insert = new JTextField();
panelbutton.add(tf_insert); btn_search = new JButton("查询");
panelbutton.add(btn_search); panelbutton.add(new JLabel());
panelbutton.add(new JLabel());
panelbutton.add(new JLabel());
panelbutton.add(new JLabel()); btn_exit = new JButton("退出窗口");
panelbutton.add(btn_exit);
this.getRootPane().setDefaultButton(btn_search);// 默认查询为获得焦点的按钮
this.setVisible(true);
} private void registerLister() {
btn_search.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
String content = tf_insert.getText().trim();
int index = cb_type.getSelectedIndex();
if (content.equals("")) {
JOptionPane.showInternalMessageDialog(AdminQueryDVDRecord.this, "查询内容不能为空");
return;
}
// record2List = recordBiz.queryHasReturnRecords(content);
// 先清除数据 ,防止数据 的累加
if (record2List != null) {
record2List.clear();
}
List<Record2> record22List = new ArrayList<Record2>();
if (index == 0) {
record22List = recordBiz.queryUserRecords(content);
} else {
record22List = recordBiz.queryDVDRecords(content);
}
refreshTable(record22List);
if (record22List.size() == 0) {
JOptionPane.showInternalMessageDialog(AdminQueryDVDRecord.this, "没有你要查询的记录!");
return;
} }
});
btn_exit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
int flag = JOptionPane.showInternalConfirmDialog(AdminQueryDVDRecord.this, "是否确定退出?", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
AdminQueryDVDRecord.this.dispose();
} }
}); } private class DVDInfoTableModel implements TableModel {
private List<Record2> record2List = null; private DVDInfoTableModel(List<Record2> record2List) {
this.record2List = record2List;
} @Override
public void addTableModelListener(TableModelListener l) {
// TODO 自动生成的方法存根 } // JTable 列的数据类型
public Class<?> getColumnClass(int columnIndex) {
// TODO 自动生成的方法存根
return String.class;
} // JTable数据 的列数
public int getColumnCount() {
// TODO 自动生成的方法存根
return 6;
} @Override
public String getColumnName(int columnIndex) {
if (columnIndex == 0) {
return "记录ID";
} else if (columnIndex == 1) {
return "影碟ID号";
} else if (columnIndex == 2) {
return "用户名";
} else if (columnIndex == 3) {
return "影碟名字";
} else if (columnIndex == 4) {
return "租赁时间";
} else if (columnIndex == 5) {
return "归还时间";
} else {
return "出错";
}
} // JTable显示 的行数
public int getRowCount() {
// TODO 自动生成的方法存根
return record2List.size();
} // 获取JTable中指定行指定单元格的数据
public Object getValueAt(int rowIndex, int columnIndex) {
Record2 record = record2List.get(rowIndex);
if (columnIndex == 0) {
return record.getId();
} else if (columnIndex == 1) {
return record.getDid();
} else if (columnIndex == 2) {
return record.getUname();
} else if (columnIndex == 3) {
return record.getDname();
} else if (columnIndex == 4) {
return record.getLendTime();
} else if (columnIndex == 5) {
return record.getReturnTime();
} else {
return "出错";
}
} @Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根
return false;
} @Override
public void removeTableModelListener(TableModelListener l) {
// TODO 自动生成的方法存根 } @Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根 } } private void refreshTable(List<Record2> record2List) {
infoTableModel = new DVDInfoTableModel(record2List);
table.setModel(infoTableModel);
} }
LoginView.java
package com.dvd.view; import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField; import com.dvd.biz.UserBiz;
import com.dvd.biz.Impl.UserBizImpl;
import com.dvd.entiy.User; public class LoginView extends JFrame { private static final long serialVersionUID = 7893951512570101893L; private UserBiz userBiz = null; private JPanel panel_main = null;
private JPanel panel_left = null;
private JPanel panel_right = null; private JLabel lb_img = null;
private JLabel lb_uname = null;
private JLabel lb_upass = null;
private JLabel lb_type = null; private JTextField tf_uname = null;
private JPasswordField pf_upass = null;
private JComboBox<String> cb_type = null; private JButton btn_login = null;
private JButton btn_register = null; public LoginView() {
userBiz = new UserBizImpl();
init();
registerListener();
} private void init() {
this.setSize(320, 220);
this.setResizable(false);
this.setLocationRelativeTo(null);// 窗口在中间打开
this.setTitle("登录窗口");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel_main = new JPanel(new GridLayout(1, 2));
panel_left = new JPanel();
panel_right = new JPanel(new GridLayout(4, 2, 10, 0)); lb_img = new JLabel(new ImageIcon(ClassLoader.getSystemResource("images/login.png")));
lb_uname = new JLabel("用 户:", JLabel.CENTER);
lb_upass = new JLabel("密 码:", JLabel.CENTER);
lb_type = new JLabel("类 型:", JLabel.CENTER); tf_uname = new JTextField(8);
pf_upass = new JPasswordField(8);
cb_type = new JComboBox<String>(new String[] { "普通用户", "管理员" }); btn_login = new JButton("登录");
btn_register = new JButton("注册");
this.getRootPane().setDefaultButton(btn_login);// 默认登录为获得焦点的按钮 panel_left.add(lb_img);
panel_right.add(lb_uname);
panel_right.add(tf_uname);
panel_right.add(lb_upass);
panel_right.add(pf_upass);
panel_right.add(lb_type);
panel_right.add(cb_type);
panel_right.add(btn_login);
panel_right.add(btn_register); panel_main.add(panel_left);
panel_main.add(panel_right); this.getContentPane().add(panel_main);
this.pack();
this.setVisible(true); } private void registerListener() {
btn_login.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
String uname = tf_uname.getText().trim();
String upass = new String(pf_upass.getPassword());
int type = cb_type.getSelectedIndex() + 1;
if (uname.equals("")) {
JOptionPane.showMessageDialog(LoginView.this, "用户名不能为空");
return;
} else if (upass.equals("")) {
JOptionPane.showMessageDialog(LoginView.this, "密码不能为空");
return;
}
User user = new User(uname, upass, type);
user = userBiz.login(user);
if (user != null) {
if (user.getType() == 1) {
new UserMainView(user);
} else {
new AdminMainView(user);
}
LoginView.this.dispose();// 打开新的窗口,旧的窗口自动关闭
} else {
JOptionPane.showMessageDialog(LoginView.this, "用户名或密码出错");
return;
}
}
}); btn_register.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
new UserRegisterView();// 弹出注册视图 }
}); } }
UserMainView.java
package com.dvd.view; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import com.dvd.entiy.User; public class UserMainView extends JFrame {
private static final long serialVersionUID = -7828161836358813128L; private JPanel panel_main = null;
private JPanel panel_wel = null;
private JDesktopPane desktopPane = null;
private JPanel panel_btn = null; private JButton btn_query_rent_dvd = null;
private JButton btn_dvd_record = null;
private JButton btn_exit = null; private JLabel lb_welcome = null;
private JLabel desk_img = null;
private User user = null; public UserMainView(User user) {
this.user = user;
init();
registerListener(this.user); } private void init() { panel_main = new JPanel(new BorderLayout());
panel_wel = new JPanel();
desktopPane = new JDesktopPane();
panel_btn = new JPanel(new GridLayout(7, 1, 0, 35)); btn_query_rent_dvd = new JButton("DVD查询租赁操作");
btn_dvd_record = new JButton("DVD租赁记录查询");
btn_exit = new JButton("退出窗口");
/*
* 快捷功能区
*/ panel_btn.setBorder(BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "快捷功能区"));
panel_btn.add(new JLabel());
panel_btn.add(new JLabel());
panel_btn.add(btn_query_rent_dvd);
panel_btn.add(btn_dvd_record);
panel_btn.add(btn_exit);
panel_btn.add(new JLabel());
panel_btn.add(new JLabel()); /*
* 欢迎区
*/
lb_welcome = new JLabel("欢 迎 " + user.getUname() + " 使 用 影 碟 租 赁 管 理 系 统");
lb_welcome.setFont(new Font("宋体", Font.BOLD, 23));
lb_welcome.setForeground(Color.BLUE);
panel_wel.add(lb_welcome);
EventQueue.invokeLater(new Runnable() { @Override
public void run() {
new Thread(new DynaminThread()).start(); }
});
/*
* 主面板
*/
ImageIcon image = new ImageIcon("src/images/main.png");
desk_img = new JLabel(image);
desk_img.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
desktopPane.add(desk_img, new Integer(Integer.MIN_VALUE)); panel_main.add(panel_wel, BorderLayout.NORTH);
panel_main.add(panel_btn, BorderLayout.EAST);
panel_main.add(desktopPane, BorderLayout.CENTER); this.getContentPane().add(panel_main);
this.setTitle("用户操作主面板");
// this.setSize(1000, 650);
this.pack();
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
} private void registerListener(User user) {
btn_query_rent_dvd.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
UserQueryDVDRecordView qdv = new UserQueryDVDRecordView(user); desktopPane.add(qdv);// 把指定的视图添加到时桌面容器中去
qdv.toFront();// 视图显示 的前面 }
});
btn_dvd_record.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
UserQueryRentDVDView qdv = new UserQueryRentDVDView();
desktopPane.add(qdv);// 把指定的视图添加到时桌面容器中去
qdv.toFront();// 视图显示 的前面 }
});
btn_exit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int flag = JOptionPane.showConfirmDialog(UserMainView.this, "是否确定退出窗口", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
System.exit(0);// 关闭窗体,并释放全部资源。
// AdminMainView.this.dispose();// 关闭窗体,释放一部分资源。
}
}
});
} /**
* 这是一个线程类,专门用来进行对欢迎Label标签进行移动
*
* @author LZC
*
*/
private class DynaminThread implements Runnable { @Override
public void run() {
while (true) {
for (int i = 780; i > -650; i--) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
lb_welcome.setLocation(i, 5);
}
} }
} }
UserQueryDVDRecordView.java
package com.dvd.view; import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List; import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel; import com.dvd.biz.DVDBiz;
import com.dvd.biz.Impl.DVDBizImpl;
import com.dvd.entiy.DVD;
import com.dvd.entiy.User; public class UserQueryDVDRecordView extends JInternalFrame { private static final long serialVersionUID = -3558209667843105955L;
private JScrollPane jScrollPane = null;// 用来保存Jtable的一个面板
private JTable table = null;// 声明JTable private JPanel panelbutton = null;// 按钮面板
private JButton btn_search = null;
private JButton btn_rent = null;
private JButton btn_exit = null;
private JComboBox<String> cb_type = null;
private JLabel lb_type = null; private DVDInfoTableModel infoTableModel = null;
DVDBiz dvdBiz = null;
List<DVD> dvdList = null;
User user = null; public UserQueryDVDRecordView(User user) {
this.user = user;
dvdBiz = new DVDBizImpl();
init();
registerListener(this.user);
} private void init() {
this.setTitle("DVD信息查询");
this.setSize(500, 450);
this.setIconifiable(true);// 窗体可最小化
this.setClosable(true);// 窗体可关闭
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLayout(new BorderLayout()); dvdList = new ArrayList<DVD>(); table = new JTable(); jScrollPane = new JScrollPane();// 创建面板
// 给面板设置边框
jScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "查询信息"));
jScrollPane.setViewportView(table);
;
this.add(jScrollPane, BorderLayout.CENTER); panelbutton = new JPanel(new GridLayout(7, 1, 10, 30));
// 给面板设置边框
panelbutton.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "查询条件"));
this.add(panelbutton, BorderLayout.EAST); refreshTable(dvdList); lb_type = new JLabel("查询类型");
panelbutton.add(lb_type);
cb_type = new JComboBox<String>(new String[] { "全部DVD", "可借DVD" });
panelbutton.add(cb_type);
btn_search = new JButton("查询");
panelbutton.add(btn_search); btn_rent = new JButton("租DVD");
panelbutton.add(btn_rent);
btn_rent.setEnabled(false);// 默认不可用 panelbutton.add(new JLabel()); panelbutton.add(new JLabel()); btn_exit = new JButton("退出窗口");
panelbutton.add(btn_exit); this.setVisible(true);
} private void registerListener(User user) {
btn_rent.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
int row = table.getSelectedRow();// 得到你所选中那行的下标
int did = (int) table.getValueAt(row, 0);
// System.out.println("id编号" + did);
int flag = dvdBiz.lendDVD(did, user.getId());
// System.out.println(user.getId());
// System.out.println("flag=" + flag);
if (flag == 1) {
JOptionPane.showInternalMessageDialog(UserQueryDVDRecordView.this, "不可借,已经借出");
return;
} else if (flag == 2) {
JOptionPane.showInternalMessageDialog(UserQueryDVDRecordView.this, "成功租到DVD");
return;
} else if (flag == 3) {
JOptionPane.showInternalMessageDialog(UserQueryDVDRecordView.this, "租DVD失败");
return;
}
}
}); table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
/// 假设选中一行,租DVD按钮可用
btn_rent.setEnabled(true);
int row = table.getSelectedRow();// 得到你所选中那行的下标 }
});
/*
* cb_type.addItemListener(new ItemListener() {
*
* @Override public void itemStateChanged(ItemEvent e) { String item =
* e.getItem().toString(); if (item.equals("可借DVD")) {
* btn_rent.setEnabled(true); }
*
* } });
*/
btn_search.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int index = cb_type.getSelectedIndex();
List<DVD> dvdList = new ArrayList<DVD>();
if (index == 0) {
dvdList = dvdBiz.queryAllDVDs();
} else {
dvdList = dvdBiz.canLendDVD();
}
refreshTable(dvdList);
if (dvdList.size() == 0) {
JOptionPane.showInternalMessageDialog(UserQueryDVDRecordView.this, "没有你要查询的记录!");
return;
} }
}); btn_exit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int flag = JOptionPane.showInternalConfirmDialog(UserQueryDVDRecordView.this, "是否确定退出?", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
UserQueryDVDRecordView.this.dispose();
}
}
}); } private class DVDInfoTableModel implements TableModel {
private List<DVD> dvdsList = null; private DVDInfoTableModel(List<DVD> dvdList) {
this.dvdsList = dvdList;
} @Override
public void addTableModelListener(TableModelListener l) {
// TODO 自动生成的方法存根 } @Override
public Class<?> getColumnClass(int columnIndex) {
// TODO 自动生成的方法存根
return String.class;
} @Override
public int getColumnCount() {
// TODO 自动生成的方法存根
return 4;
} @Override
public String getColumnName(int columnIndex) {
if (columnIndex == 0) {
return "影碟ID";
} else if (columnIndex == 1) {
return "影碟名字";
} else if (columnIndex == 2) {
return "影碟借出次数";
} else if (columnIndex == 3) {
return "影碟状态";
} else {
return "出错";
}
} @Override
public int getRowCount() {
// TODO 自动生成的方法存根
return dvdsList.size();
} @Override
public Object getValueAt(int rowIndex, int columnIndex) {
DVD dvd = dvdsList.get(rowIndex);
if (columnIndex == 0) {
return dvd.getId();
} else if (columnIndex == 1) {
return dvd.getDname();
} else if (columnIndex == 2) {
return dvd.getDcount();
} else if (columnIndex == 3) {
return "" + (dvd.getStatus() == 1 ? "可借" : "已借");
} else {
return "出错";
}
} @Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根
return false;
} @Override
public void removeTableModelListener(TableModelListener l) {
// TODO 自动生成的方法存根 } @Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根 } } // 刷新Jtable并显示数据
private void refreshTable(List<DVD> dvdList) {
infoTableModel = new DVDInfoTableModel(dvdList);
table.setModel(infoTableModel);
}
}
UserQueryRentDVDView.java
package com.dvd.view; import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List; import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel; import com.dvd.biz.DVDBiz;
import com.dvd.biz.Impl.DVDBizImpl;
import com.dvd.entiy.DVD; public class UserQueryRentDVDView extends JInternalFrame { private static final long serialVersionUID = -3558209667843105955L;
private JScrollPane jScrollPane = null;// 用来保存Jtable的一个面板
private JTable table = null;// 声明JTable private JPanel panelbutton = null;// 按钮面板
private JButton btn_search = null;
private JButton btn_return = null;
private JButton btn_exit = null;
private JComboBox<String> cb_type = null;
private JLabel lb_type = null;
private DVDInfoTableModel infoTableModel = null;
DVDBiz dvdBiz = null; public UserQueryRentDVDView() {
dvdBiz = new DVDBizImpl();
init();
registerListener();
} private void init() {
this.setTitle("DVD租赁记录查询");
this.setSize(500, 450);
this.setIconifiable(true);// 窗体可最小化
this.setClosable(true);// 窗体可被关闭
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLayout(new BorderLayout()); table = new JTable();
jScrollPane = new JScrollPane();// 创建面板
// 给面板设置边框
jScrollPane
.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "本人租赁记录查询 "));
jScrollPane.setViewportView(table);
this.add(jScrollPane, BorderLayout.CENTER); panelbutton = new JPanel(new GridLayout(7, 1, 10, 30));
// 给面板设置边框
panelbutton.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(null, null), "查询条件"));
this.add(panelbutton, BorderLayout.EAST);
lb_type = new JLabel("查询类型");
panelbutton.add(lb_type);
cb_type = new JComboBox<String>(new String[] { "全部DVD", "未还DVD" });
panelbutton.add(cb_type); btn_search = new JButton("查询");
panelbutton.add(btn_search); btn_return = new JButton("还DVD");
panelbutton.add(btn_return);
btn_return.setEnabled(false);// 默认不可用 panelbutton.add(new JLabel()); panelbutton.add(new JLabel()); btn_exit = new JButton("退出窗口");
panelbutton.add(btn_exit); this.setVisible(true);
} private void registerListener() {
btn_return.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();// 得到你所选中那行的下标
int rid = (int) table.getValueAt(row, 0);
// System.out.println(rid);
int flag = dvdBiz.returnDVD(rid);
System.out.println(flag);
if (flag == 1) {
JOptionPane.showInternalMessageDialog(UserQueryRentDVDView.this, "DVD已经归还");
return;
} else if (flag == 2) {
JOptionPane.showInternalMessageDialog(UserQueryRentDVDView.this, "DVD已经归还");
return;
} else if (flag == 3) {
JOptionPane.showInternalMessageDialog(UserQueryRentDVDView.this, "归还成功");
return;
} else if (flag == 4) {
JOptionPane.showInternalMessageDialog(UserQueryRentDVDView.this, "归还失败");
return;
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
/// 假设选中一行,还DVD按钮可用
btn_return.setEnabled(true); }
}); btn_search.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int index = cb_type.getSelectedIndex();
List<DVD> dvdList = new ArrayList<DVD>();
if (index == 0) {
dvdList = dvdBiz.queryAllDVDs();
} else {
dvdList = dvdBiz.hasLendedDvD();
}
refreshTable(dvdList);
if (dvdList.size() == 0) {
JOptionPane.showInternalMessageDialog(UserQueryRentDVDView.this, "没有你要查询的记录!");
return;
} }
});
btn_exit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
int flag = JOptionPane.showInternalConfirmDialog(UserQueryRentDVDView.this, "是否确定退出?", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
UserQueryRentDVDView.this.dispose();
}
}
});
} private class DVDInfoTableModel implements TableModel {
private List<DVD> dvdsList = null; private DVDInfoTableModel(List<DVD> dvdList) {
this.dvdsList = dvdList;
} @Override
public void addTableModelListener(TableModelListener l) {
// TODO 自动生成的方法存根 } @Override
public Class<?> getColumnClass(int columnIndex) {
// TODO 自动生成的方法存根
return String.class;
} @Override
public int getColumnCount() {
// TODO 自动生成的方法存根
return 4;
} @Override
public String getColumnName(int columnIndex) {
if (columnIndex == 0) {
return "影碟ID";
} else if (columnIndex == 1) {
return "影碟名字";
} else if (columnIndex == 2) {
return "影碟借出次数";
} else if (columnIndex == 3) {
return "影碟状态";
} else {
return "出错";
}
} @Override
public int getRowCount() {
// TODO 自动生成的方法存根
return dvdsList.size();
} @Override
public Object getValueAt(int rowIndex, int columnIndex) {
DVD dvd = dvdsList.get(rowIndex);
if (columnIndex == 0) {
return dvd.getId();
} else if (columnIndex == 1) {
return dvd.getDname();
} else if (columnIndex == 2) {
return dvd.getDcount();
} else if (columnIndex == 3) {
return "" + (dvd.getStatus() == 1 ? "可借" : "已借");
} else {
return "出错";
}
} @Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根
return false;
} @Override
public void removeTableModelListener(TableModelListener l) {
// TODO 自动生成的方法存根 } @Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根 } } // 刷新Jtable并显示数据
private void refreshTable(List<DVD> dvdList) {
infoTableModel = new DVDInfoTableModel(dvdList);
table.setModel(infoTableModel);
} }
// UserQueryRentDVDView
UserRegisterView.java
package com.dvd.view; import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; 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; import com.dvd.biz.UserBiz;
import com.dvd.biz.Impl.UserBizImpl;
import com.dvd.dao.UserDao;
import com.dvd.dao.impl.UserDaoImpl;
import com.dvd.entiy.User; public class UserRegisterView extends JFrame {
private static final long serialVersionUID = 7893951512570101893L;
private JPanel panel_main = null;
private JPanel panel01 = null;
private JPanel panel02 = null;
private JPanel panel03 = null;
private JPanel panel04 = null;
private JPanel panel05 = null; private JLabel lb_name = null;
private JLabel lb_init_upass = null;
private JLabel lb_confirm_upass = null; private JTextField tf_name = null;
private JPasswordField pf_init_upass = null;
private JPasswordField pf_confirm_upass = null; private JButton btn_confirm = null;
private JButton btn_back = null; UserDao userDao = null;
UserBiz userBiz = null; public UserRegisterView() {
userDao = new UserDaoImpl();
userBiz = new UserBizImpl();
init();
registerListener();
} private void init() {
this.setSize(450, 260);
this.setResizable(false);
this.setLocationRelativeTo(null);// 窗口在中间打开
this.setTitle("用户注册窗口");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel_main = new JPanel(new GridLayout(5, 1));
JPanel panel01 = new JPanel();
JPanel panel02 = new JPanel();
JPanel panel03 = new JPanel();
JPanel panel04 = new JPanel();
JPanel panel05 = new JPanel(); lb_name = new JLabel("用户名");
lb_name.setFont(new Font("宋体", Font.BOLD, 15));
lb_init_upass = new JLabel("初始化密码");
lb_init_upass.setFont(new Font("宋体", Font.BOLD, 15));
lb_confirm_upass = new JLabel("确认密码");
lb_confirm_upass.setFont(new Font("宋体", Font.BOLD, 15)); tf_name = new JTextField(15);
pf_init_upass = new JPasswordField(15);
pf_confirm_upass = new JPasswordField(15); btn_confirm = new JButton("确认提交");
btn_back = new JButton("退出"); panel02.add(lb_name);
panel02.add(tf_name);
panel03.add(lb_init_upass);
panel03.add(pf_init_upass);
panel04.add(lb_confirm_upass);
panel04.add(pf_confirm_upass);
panel05.add(btn_confirm);
panel05.add(btn_back); panel_main.add(panel01);
panel_main.add(panel02);
panel_main.add(panel03);
panel_main.add(panel04);
panel_main.add(panel05); this.getContentPane().add(panel_main); this.getRootPane().setDefaultButton(btn_confirm);// 默认获得焦点的按钮
this.setVisible(true); } private void registerListener() {
// 退出按钮
btn_back.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// int flag =
// JOptionPane.showInternalConfirmDialog(UserRegisterView.this,
// "是否退出注册?", "退出信息",
// JOptionPane.YES_NO_OPTION);
int flag = JOptionPane.showConfirmDialog(UserRegisterView.this, "是否退出注册?", "确认信息",
JOptionPane.YES_NO_OPTION);
if (flag == JOptionPane.YES_OPTION) {
UserRegisterView.this.dispose();// 窗口自动关闭
}
}
});
// 注册按钮
btn_confirm.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
String uname = tf_name.getText();
String init_upass = new String(pf_init_upass.getPassword());
String upass = new String(pf_confirm_upass.getPassword());
if (uname.equals("")) {
JOptionPane.showMessageDialog(UserRegisterView.this, "用户名不能为空");
return;
} else if (init_upass.equals("")) {
JOptionPane.showMessageDialog(UserRegisterView.this, "初始化密码不能为空");
return;
} else if (upass.equals("")) {
JOptionPane.showMessageDialog(UserRegisterView.this, "确认密码不能为空");
return;
}
User user = new User(uname, upass, 1); int flag = userBiz.registerUser(user);
if (flag == 1) {
JOptionPane.showMessageDialog(UserRegisterView.this, "用户名已存在");
return;
} else if (flag == 2) {
JOptionPane.showMessageDialog(UserRegisterView.this, "注册成功");
return;
} else if (flag == 3) {
JOptionPane.showMessageDialog(UserRegisterView.this, "注册失败");
return;
}
}
}); } }
TestLogin.java
package com.dvd.text; import com.dvd.view.LoginView; public class TestLogin {
public static void main(String[] args) {
new LoginView();
}
}
看了那么多代码,来看看运行怎么样
最后就是红色这里还没完善,有待更新
DVD租赁系统的更多相关文章
- 《Java从入门到放弃》JavaSE篇:综合练习——单身狗租赁系统(数组版)
因为现在只学习了基本语法,所以在综合练习之前,先补充关于方法概念. 方法的作用:把一系列的代码放在一起,然后再取个别名.之后通过这个别名的调用,就相当于执行了这一系列的代码. 方法的语法:([]中的内 ...
- 《Java从入门到放弃》JavaSE入门篇:练习——单身狗租赁系统
今天,我们要玩个大的!!! 我们把之前使用数组做的这个单身狗系统改版成数据库版本,并且使用面向对象里面的一些简单思想.如果有不知道这个系统的看官,请跳转到目录页,然后再选择单身狗系统(数组版)先围观五 ...
- Java汽车租赁系统[源码+数据库]
系统名称 Java汽车租赁系统 (源码在文末) 系统概要 汽车租赁系统总共分为两个大的模块,分别是系统模块和业务模块.其中系统模块和业务模块底下又有其子模块. 功能模块 一.业务模块 1.客户管理 ...
- 深入.NET和C#的小型汽车租赁系统的框架
前言:写这个小型系统之前呢,我们应该要猜测可能要用到哪些知识点. 那么对于这个小型系统:主要用到了如下的知识: 封装,集合(ArrayList和HashTable)和泛型和非泛型集合(泛型:List ...
- 简易DVD查询系统
==========DVD管理系统========== 这是DVD任务管理器的主界面: package day20181224; import java.text.ParseException; im ...
- Java代码~~汽车租赁系统
租车信息: 输出结果: 代码: 1.先定义抽象类(汽车类:Moto) package cn.aura.demo01; public abstract class Moto { //公共属性 priva ...
- 一种基于Java Swing/HTML/MySQL的汽车租赁系统
该项目是一个Java的课程作业(大二),主要运用Java.Swing.HTML.MySQL,实现基本的租车逻辑.界面可视化.信息导出.数据存储等功能.实现管理员.用户两种角色登录,并结合Java开发中 ...
- C#汽车租赁系统 完整版
Truck.cs类 //卡车类 public class Truck : Vehicle1 { //重载 public int Load { get; set; } //构造函数 public T ...
- C#汽车租赁系统
类图: 父类(车类,抽象类) /// <summary> /// 车辆基本信息类.搞一个抽象类玩玩 /// </summary> public abstract class V ...
随机推荐
- Go语言_range(范围)理解
一.Go语言中的range Go 语言中 range 关键字用于 for循环中迭代数组(array).切片(slice).链表(channel)或集合(map)的元素: 在数组和切片中它返回元素的索引 ...
- Netbeans 8.1 检测不到Tomcat8.5.3以上版本已经启动的Bug
Tomcat实际上已经启动,但是netbeans就是检测不到,只要在server.xml中,找到http/1.1的connector 添加 属性 server="Apache-Coyote/ ...
- Sysfs文件系统接口调试
首先需要初始化操作: s32 gtp_sysfs_init(void) { s32 ret ; debug_kobj = kobject_create_and_add("gtp", ...
- [Cubieboard] 镜像资源汇总
Linaro Server 14.04 (SDCard) 下载:cb2-lubuntu-server-tsd-tfcard-v2.0.img.gz 内核:GNU/Linux 3.4.79 armv7l ...
- 八、K3 WISE 开发插件《工业单据老单插件中获取登陆用户名》
备注:如果是BOS新单,都有获取用户名的方法.在单据有m_BillInterface.K3Lib.User.UserId,在序时薄有m_ListInterface.K3Lib.User.UserID ...
- Unity3D 批处理场景的工具
//场景的批量处理器 public static class OperateScene { public const string SceneDir = "Assets/Scene/&quo ...
- fclose函数无响应
现象:win32程序在退出时无响应,当一步步跟踪代码时走到fclose. 原因:打开文件在一个线程中,写文件时在另一个线程,在open和write文件时均正常,只有在fclose时出现无响应. 解决: ...
- ABP之事件总线(3)
承接上一篇时间总线的学习,在上一篇中我们实现了取消显式注册事件的方式,采用使用反射的方式.这样的好处可以解除Publisher和Scriber的显式依赖,但是问题又来了,因为我们只有Publisher ...
- CentOS安装中文支持包
修改配置文件 LANG="zh_CN.UTF-8" 改为中文字符集 然后在查看更改后的系统语言变量 [root@5c46832b5c01 ~]# locale locale: Ca ...
- element UI 导航栏根据路径来确定默认选中
<template> <el-menu :default-active="activedMenu($route.path)" class="el-men ...