java书店系统毕业设计 用户模块(3)
本文实例为大家分享了java书店系统毕业设计第3篇,供大家参考,具体内容如下
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
/**
*
* @author __USER__
*/
public class listPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private JFrame mainFrame = null;
public listPanel(JFrame mainFrame) {//初始化
this.mainFrame = mainFrame;
initComponents();
myInitDate();
}
@SuppressWarnings("unchecked")
public listPanel(JFrame mainFrame, List<UserModel> list) {
this.mainFrame = mainFrame;
initComponents();
jList.setListData(list.toArray());
}
@SuppressWarnings("unchecked")
private void myInitDate() {
List<UserModel> list = UserEbiFactory.getUserEbi().getAll();
jList.setListData(list.toArray());
}
//***这一段是自动生成的,下面将不再写***
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jList = new javax.swing.JList();
btnToDelete = new javax.swing.JButton();
btnToUpDate = new javax.swing.JButton();
btnToQuery = new javax.swing.JButton();
btnToAdd = new javax.swing.JButton();
setBackground(new java.awt.Color(0, 153, 51));
setMinimumSize(new java.awt.Dimension(800, 600));
setLayout(null);
jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 36));
jLabel1.setForeground(new java.awt.Color(204, 0, 204));
jLabel1.setText("\u7528\u6237\u7ba1\u7406");
add(jLabel1);
jLabel1.setBounds(330, 100, 190, 60);
jScrollPane1.setForeground(new java.awt.Color(0, 51, 153));
jScrollPane1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
jList.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24));
jList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "" };
public int getSize() {
return strings.length;
}
public Object getElementAt(int i) {
return strings[i];
}
});
jScrollPane1.setViewportView(jList);
add(jScrollPane1);
jScrollPane1.setBounds(190, 170, 410, 220);
btnToDelete.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
btnToDelete.setText("\u5220\u9664\u7528\u6237");
btnToDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnToDeleteActionPerformed(evt);
}
});
add(btnToDelete);
btnToDelete.setBounds(240, 470, 110, 40);
btnToUpDate.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
btnToUpDate.setText("\u4fee\u6539\u7528\u6237");
btnToUpDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnToUpDateActionPerformed(evt);
}
});
add(btnToUpDate);
btnToUpDate.setBounds(430, 470, 110, 40);
btnToQuery.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
btnToQuery.setText("\u67e5\u627e\u7528\u6237");
btnToQuery.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnToQueryActionPerformed(evt);
}
});
add(btnToQuery);
btnToQuery.setBounds(600, 470, 110, 40);
btnToAdd.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
btnToAdd.setText("\u6dfb\u52a0\u7528\u6237");
btnToAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnToAddActionPerformed(evt);
}
});
add(btnToAdd);
btnToAdd.setBounds(60, 470, 110, 40);
}// </editor-fold>
//GEN-END:initComponents
private void btnToQueryActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new QueryPanel(mainFrame));
mainFrame.validate();
}
private void btnToUpDateActionPerformed(java.awt.event.ActionEvent evt) {
if (jList.getSelectedValue() == null) {
JOptionPane.showMessageDialog(this, "请选择要修改的用户");
return;
}
String uuid = jList.getSelectedValue().toString().split(",")[0];
mainFrame.setContentPane(new UpdatePanel(mainFrame, uuid));
mainFrame.validate();
}
private void btnToDeleteActionPerformed(java.awt.event.ActionEvent evt) {
if (jList.getSelectedValue() == null) {
JOptionPane.showMessageDialog(this, "请选择要删除的用户");
return;
}
String uuid = jList.getSelectedValue().toString().split(",")[0];
mainFrame.setContentPane(new DeletePanel(mainFrame, uuid));
mainFrame.validate();
}
private void btnToAddActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new AddPanel(mainFrame));
mainFrame.validate();
}
//***这一段是自动生成的,下面将不再写***
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton btnToAdd;
private javax.swing.JButton btnToDelete;
private javax.swing.JButton btnToQuery;
private javax.swing.JButton btnToUpDate;
private javax.swing.JLabel jLabel1;
private javax.swing.JList jList;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
}
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.common.UserTypeEnum;
import cn.hncu.bookStore.user.vo.UserModel;
/**
*
* @author __USER__
*/
public class AddPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private JFrame mainFrame = null;
/** Creates new form AddPanel */
public AddPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
myinitDate();
}
@SuppressWarnings("unchecked")
private void myinitDate() {
combType.removeAllItems();
for (UserTypeEnum utm:UserTypeEnum.values()) {
combType.addItem(utm.getName());
}
}
//***自动生成代码略过***
// </editor-fold>
//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new listPanel(mainFrame));
mainFrame.validate();
}
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
String strName = tfdName.getText().trim();
String strUuid = tfdUuid.getText().trim();
String strPwd = new String(tfdPwd.getPassword());
String strPwd2 =new String(tfdPwd2.getPassword());
if (!strPwd.equals(strPwd2)) {
JOptionPane.showMessageDialog(this, "密码错误!");
return;
}
String strCombType = combType.getSelectedItem().toString();
UserModel um = new UserModel();
um.setName(strName);
um.setUuid(strUuid);
um.setPwd(strPwd);
um.setType(UserTypeEnum.getTypeByName(strCombType));
boolean boo = UserEbiFactory.getUserEbi().create(um);
if (boo) {
btnCancelActionPerformed(null);
} else {
JOptionPane.showMessageDialog(this, "用户已存在!");
return;
}
}
//***自动生成代码略过***
//GEN-BEGIN
}
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.common.UserTypeEnum;
import cn.hncu.bookStore.user.vo.UserModel;
/**
*
* @author __USER__
*/
public class DeletePanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private JFrame mainFrame = null;
private String uuid;
UserEbi ebi = UserEbiFactory.getUserEbi();
/** Creates new form AddPanel */
public DeletePanel(JFrame mainFrame, String uuid) {
this.mainFrame = mainFrame;
this.uuid = uuid;
initComponents();
myinitDate();
}
@SuppressWarnings("unchecked")
private void myinitDate() {
UserModel um = ebi.getSingle(uuid);
tfdUuid.setText(uuid);
tfdUuid.setEnabled(false);
tfdName.setText(um.getName());
tfdName.setEnabled(false);
tfdPwd.setText(um.getPwd());
tfdPwd.setEnabled(false);
tfdPwd2.setText(um.getPwd());
tfdPwd2.setEnabled(false);
combType.removeAllItems();
for (UserTypeEnum utm : UserTypeEnum.values()) {
combType.addItem(utm.getName());
}
combType.setSelectedIndex(um.getType());
combType.setEnabled(false);
}
//***自动生成代码略过***
// </editor-fold>
//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new listPanel(mainFrame));
mainFrame.validate();
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
boolean boo = ebi.delete(uuid);
if (boo) {
btnCancelActionPerformed(null);
} else {
JOptionPane.showMessageDialog(this, "删除用户失败,用户已不存在!");
return;
}
}
//***自动生成代码略过***
//GEN-BEGIN
}
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.common.UserTypeEnum;
import cn.hncu.bookStore.user.vo.UserModel;
/**
*
* @author __USER__
*/
public class UpdatePanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private JFrame mainFrame = null;
private String uuid;
UserEbi ebi = UserEbiFactory.getUserEbi();
/** Creates new form AddPanel */
public UpdatePanel(JFrame mainFrame, String uuid) {
this.mainFrame = mainFrame;
this.uuid = uuid;
initComponents();
myinitDate();
}
@SuppressWarnings("unchecked")
private void myinitDate() {
UserModel um = ebi.getSingle(uuid);
tfdUuid.setText(uuid);
tfdUuid.setEnabled(false);
tfdName.setText(um.getName());
tfdPwd.setText(um.getPwd());
tfdPwd2.setText(um.getPwd());
combType.removeAllItems();
for (UserTypeEnum utm : UserTypeEnum.values()) {
combType.addItem(utm.getName());
}
combType.setSelectedIndex(um.getType());
}
//***自动生成代码略过***
// </editor-fold>
//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new listPanel(mainFrame));
mainFrame.validate();
}
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
String strName = tfdName.getText().trim();
String strUuid = tfdUuid.getText().trim();
String strPwd = new String(tfdPwd.getPassword());
String strPwd2 =new String(tfdPwd2.getPassword());
if (!strPwd.equals(strPwd2)) {
JOptionPane.showMessageDialog(this, "密码错误!");
return;
}
String strCombType = combType.getSelectedItem().toString();
UserModel um = new UserModel();
um.setName(strName);
um.setUuid(strUuid);
um.setPwd(strPwd);
um.setType(UserTypeEnum.getTypeByName(strCombType));
boolean boo = UserEbiFactory.getUserEbi().update(um);
if (boo) {
btnCancelActionPerformed(null);
} else {
JOptionPane.showMessageDialog(this, "用户已存在!");
return;
}
}
//***自动生成代码略过***
//GEN-BEGIN
}
import java.util.List;
import javax.swing.JFrame;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.common.UserTypeEnum;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
/**
*
* @author __USER__
*/
public class QueryPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private JFrame mainFrame = null;
/** Creates new form AddPanel */
public QueryPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
myinitDate();
}
@SuppressWarnings("unchecked")
private void myinitDate() {
combType.removeAllItems();
combType.addItem("请选择");
for (UserTypeEnum utm : UserTypeEnum.values()) {
combType.addItem(utm.getName());
}
}
//***自动生成代码略过***
// </editor-fold>
//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new listPanel(mainFrame));
mainFrame.validate();
}
private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
String strName = tfdName.getText().trim();
String strUuid = tfdUuid.getText().trim();
String strCombType = combType.getSelectedItem().toString();
UserQueryModel uqm=new UserQueryModel();
uqm.setName(strName);
uqm.setUuid(strUuid);
int type=0;
if(combType.getSelectedIndex()>0){
type=UserTypeEnum.getTypeByName(strCombType);
}
uqm.setType(type);
List<UserModel> list= UserEbiFactory.getUserEbi().getByCondition(uqm);
mainFrame.setContentPane(new listPanel(mainFrame,list));
mainFrame.validate();
}
//***自动生成代码略过***
//GEN-BEGIN
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
以上是 java书店系统毕业设计 用户模块(3) 的全部内容, 来源链接: utcz.com/p/210563.html