标签:art except tco 选中 子窗体 sts 实体 ane splay
Start.java
就是输出点东西
1 package edu.uc.ui.cli; 2 3 import edu.uc.bean.Member; 4 import edu.uc.service.MemberService; 5 import edu.uc.service.impl.MemberServiceImpl; 6 7 public class Start { 8 public static void main(String []args) { 9 MemberService memberService = new MemberServiceImpl(); 10 11 String name= "t1"; 12 Member bean = memberService.loadByName(name); 13 14 System.out.println(bean.getUserId()); 15 System.out.println(bean.getUserName()); 16 System.out.println(bean.getUserPass()); 17 System.out.println(bean.getNickName()); 18 System.out.println(bean.getStatus()); 19 } 20 }
StartList.java
数据库的数据都输出来
1 package edu.uc.ui.cli; 2 3 import java.util.*; 4 5 import edu.uc.bean.Member; 6 import edu.uc.service.MemberService; 7 import edu.uc.service.impl.MemberServiceImpl; 8 9 public class StartList { 10 public static void main(String []args) { 11 MemberService memberService = new MemberServiceImpl(); 12 13 String name= "t1"; 14 List<Member> list= memberService.list(); 15 16 for(Member bean:list) { 17 System.out.println(bean.getUserId()+"\t"+bean.getUserName()+"\t"+bean.getUserPass()+"\t"+bean.getNickName()+"\t"+bean.getNickName()+"\t"); 18 //System.out.println(bean.getUserName()+"\t"); 19 //System.out.println(bean.getUserPass()+"\t"); 20 //System.out.println(bean.getNickName()+"\t"); 21 //System.out.println(bean.getNickName()+"\t"); 22 } 23 } 24 }
StartListByName.java
通过名字输出数据
1 package edu.uc.ui.cli; 2 3 import java.util.List; 4 5 import edu.uc.bean.Member; 6 import edu.uc.service.MemberService; 7 import edu.uc.service.impl.MemberServiceImpl; 8 9 public class StartListByName { 10 11 public static void main(String[] args) { 12 13 MemberService memberService = new MemberServiceImpl(); 14 15 String name = "t"; 16 List<Member> list = memberService.listByName(name); 17 18 for(Member bean : list) { 19 System.out.print(bean.getUserId()+"\t"); 20 System.out.print(bean.getUserName()+"\t"); 21 System.out.print(bean.getUserPass()+"\t"); 22 System.out.print(bean.getNickName()+"\t"); 23 System.out.println(bean.getStatus()); 24 } 25 26 27 28 } 29 30 }
上面的是界面:我就不解释了,直接给代码(按照顺序的):
package edu.uc.ui.win; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; import javax.swing.*; import com.liuvei.common.SysFun; import com.liuvei.common.win.AFrame; import com.liuvei.common.win.IdText; import com.liuvei.common.win.IdTextModel; import edu.uc.bean.Member; import edu.uc.service.MemberService; import edu.uc.service.impl.MemberServiceImpl; public class LoginFrm extends AFrame{ public LoginFrm() { init(); } private JLabel lblLoginName; private JLabel lblLoginPwd; private JLabel lblLoginType; private JTextField txtLoginName; private JPasswordField txtLoginPwd; private JComboBox<IdText> cboLoginType; private JButton btnLogin; private JButton btnClose; private JLabel lblMsg; //上面是看界面需要什么。你就创建上面变量 @Override protected void initComponent() { // TODO Auto-generated method stub this.moveCenter();// this.setTitle("管理员登录"); lblLoginName = new JLabel(); lblLoginName.setText("账号:"); lblLoginName.setBounds(80, 50,50, 30); container.add(lblLoginName); lblLoginPwd = new JLabel(); lblLoginPwd.setText("密码:"); lblLoginPwd.setBounds(80, 90,50, 30); container.add(lblLoginPwd); lblLoginType = new JLabel(); lblLoginType.setText("类型:"); lblLoginType.setBounds(80, 130,50, 30); container.add(lblLoginType); txtLoginName = new JTextField(); txtLoginName.setBounds(150, 50, 160, 30); txtLoginPwd = new JPasswordField(); txtLoginPwd.setBounds(150, 90, 160, 30); cboLoginType = new JComboBox<IdText>(); cboLoginType.setBounds(150, 130, 160, 30); container.add(txtLoginName); container.add(txtLoginPwd); container.add(cboLoginType); btnLogin = new JButton(); btnClose = new JButton(); btnLogin.setText("登录"); btnClose.setText("退出"); btnLogin.setBounds(100, 200, 80, 40); btnClose.setBounds(200, 200, 80, 40); container.add(btnLogin); container.add(btnClose); lblMsg = new JLabel(); lblMsg.setForeground(Color.RED); //lblMsg.setText("提示:xxxxxxx."); lblMsg.setBounds(90, 160, 160, 30); container.add(lblMsg); } @Override protected void initEvent() { // TODO Auto-generated method stub btnLogin.addActionListener(event ->{ btnLogin_click(event); }); btnClose.addActionListener(event->{ btnClose_click(event); }); } private void btnLogin_click(ActionEvent event) { // TODO Auto-generated method stub //lblMsg.setText("点击了登录按钮。"); lblMsg.setText(""); String vLoginName = txtLoginName.getText().trim(); String vLoginPwd = txtLoginPwd.getText().trim(); Long vLoginType = 0L; IdText item = (IdText)cboLoginType.getModel().getSelectedItem(); if(item!= null) { vLoginType = item.getId(); } if(SysFun.isNullOrEmpty(vLoginName)) { lblMsg.setText("提示:请输入账号。"); return; } if(SysFun.isNullOrEmpty(vLoginPwd)) { lblMsg.setText("提示:请输入密码。"); return; } MemberService memberService =new MemberServiceImpl(); Member bean = memberService.loadByName(vLoginName); if(bean==null) { lblMsg.setText("提示:账号不存在"); return; } if(!vLoginPwd.equals(bean.getUserPass())) { lblMsg.setText("提示:密码错误"); return; } //如果是管理员,则显示管理员主窗体 if(vLoginType == 0) { if("".equals(bean.getStatus())) { //lblMsg.setText("提示:显示管理员主窗体。"); edu.uc.ui.win.manager.MainFrm mainFrm = new edu.uc.ui.win.manager.MainFrm(); mainFrm.setVisible(true); mainFrm.loginName =vLoginName; mainFrm.loginFrm = this; mainFrm.showLoginName(); this.setVisible(false); txtLoginName.setText(""); txtLoginPwd.setText(""); return; } lblMsg.setText("提示:登录出错。"); } } private void btnClose_click(ActionEvent event) { // TODO Auto-generated method stub //lblMsg.setText("点击了退出按钮。"); lblMsg.setText(""); exit(); } @Override protected void initLoad() { // TODO Auto-generated method stub showLoginType(); } private void showLoginType() { List<IdText> list = new ArrayList<IdText>(); list.add(new IdText(0L,"管理员")); list.add(new IdText(1L,"教师")); list.add(new IdText(2L,"学生")); //设置JComboBox对象的数据源 cboLoginType.setModel(new IdTextModel(list)); //设置JComboBox的数据源的当前选中的项目 cboLoginType.getModel().setSelectedItem(new IdText(0L)); } @Override protected void window_closing(WindowEvent arg0) { // TODO Auto-generated method stub exit(); } }
1 package edu.uc.ui.win; 2 3 import javax.swing.JFrame; 4 5 public class StartWin { 6 7 public static void main(String[] args) { 8 9 JFrame frm = null; 10 frm = new LoginFrm(); 11 //frm = new edu.uc.ui.win.manager.MainFrm(); 12 13 frm.setVisible(true); 14 15 } 16 }
1 package edu.uc.ui.win.manager; 2 3 import java.awt.event.WindowEvent; 4 5 import com.liuvei.common.win.AFrame; 6 7 public class AboutFrm extends AFrame{ 8 9 public AboutFrm() { 10 this.init(); 11 } 12 13 @Override 14 protected void initComponent() { 15 // TODO Auto-generated method stub 16 this.setTitle("关于"); 17 } 18 19 @Override 20 protected void initEvent() { 21 // TODO Auto-generated method stub 22 23 } 24 25 @Override 26 protected void initLoad() { 27 // TODO Auto-generated method stub 28 29 } 30 31 @Override 32 protected void window_closing(WindowEvent arg0) { 33 // TODO Auto-generated method stub 34 close(); 35 } 36 37 }
package edu.uc.ui.win.manager; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JMenuItem; import com.liuvei.common.SysFun; import com.liuvei.common.win.AFrame; import com.liuvei.common.win.AFrameMain; import com.liuvei.common.win.InnerFactory; public class MainFrm extends AFrameMain{ public MainFrm() { init(); } public String loginName; public void showLoginName() { if(!SysFun.isNullOrEmpty(this.loginName)) { String title = this.getTitle(); title +="-【"+loginName+"】"; this.setTitle(title); } } private JMenuItem itemA1; private JMenuItem itemA2; private JMenuItem itemB1; private JMenuItem itemB2; private JMenuItem itemB3; private JMenuItem itemC1; private JMenuItem itemC2; private JMenuItem itemC3; private JMenuItem itemZ1; private JMenuItem itemZ2; @Override protected void initComponent() { // TODO Auto-generated method stub this.setTitle("后台管理-学生信息管理系统"); itemA1 = new JMenuItem(); itemA1.setText("注销"); menuA.add(itemA1); itemA2 = new JMenuItem(); itemA2.setText("退出"); menuA.add(itemA2); itemB1 = new JMenuItem(); itemB1.setText("账号管理"); menuB.add(itemB1); itemB2 = new JMenuItem(); itemB2.setText("基础管理2"); menuB.add(itemB2); itemB3 = new JMenuItem(); itemB3.setText("基础管理3"); menuB.add(itemB3); itemC1 = new JMenuItem(); itemC1.setText("高级管理1"); menuC.add(itemC1); itemC2 = new JMenuItem(); itemC2.setText("高级管理2"); menuC.add(itemC2); itemC3 = new JMenuItem(); itemC3.setText("高级管理3"); menuC.add(itemC3); itemZ1 = new JMenuItem(); itemZ1.setText("帮助"); menuZ.add(itemZ1); itemZ2 = new JMenuItem(); itemZ2.setText("关于"); menuZ.add(itemZ2); } @Override protected void initEvent() { // TODO Auto-generated method stub } @Override protected void initLoad() { // TODO Auto-generated method stub itemZ1.addActionListener(event ->{ itemZ1_click(event); }); itemZ2.addActionListener(event ->{ itemZ2_click(event); }); itemA1.addActionListener(event ->{ itemA1_click(event); }); itemA2.addActionListener(event ->{ itemA2_click(event); }); itemB1.addActionListener(event ->{ itemB1_click(event); }); } public JFrame loginFrm = null; private void itemA1_click(ActionEvent event) { // TODO Auto-generated method stub if(loginFrm != null) { loginFrm.setVisible(true); this.close(); } } private void itemA2_click(ActionEvent event) { // TODO Auto-generated method stub exit(); } public String modelName = "member"; private void itemB1_click(ActionEvent event) { // TODO Auto-generated method stub String vKeySuffix = modelName; String vClassFullName = MemberListFrm.class.getName(); String vKey = vClassFullName+":"+vKeySuffix+""; String vTitle = "用户管理"+""; InnerFactory.generalInner(modelName, vKey, vTitle, vClassFullName, MainFrm.this); } private void itemZ1_click(ActionEvent event) { // TODO Auto-generated method stub //this.setTitle("你点击了帮助菜单项"); } private void itemZ2_click(ActionEvent event) { // TODO Auto-generated method stub //this.setTitle("你点击了关于菜单项"); AboutFrm aboutFrm = new AboutFrm(); aboutFrm.setVisible(true); } @Override protected void window_closing(WindowEvent arg0) { // TODO Auto-generated method stub exit(); } }
package edu.uc.ui.win.manager; import java.util.ArrayList; import java.util.List; import javax.swing.JComboBox; import javax.swing.JPasswordField; import com.liuvei.common.SysFun; import com.liuvei.common.win.AInnerEdit; import com.liuvei.common.win.KeyText; import com.liuvei.common.win.KeyTextModel; import edu.uc.bean.Member; import edu.uc.service.MemberService; import edu.uc.service.impl.MemberServiceImpl; public class MemberInsertFrm extends AInnerEdit{ public MemberInsertFrm() { initFrm(); } public void initFrm() { editComponent(); editEvent(); editLoad(); } public void editComponent() { this.lblMsg.setText("提示:实现账号的添加。"); this.lblTitle00.setText("账 号:"); this.lblTitle00.setBounds(230, 30, 80, 30); pnlBody.add(lblTitle00); this.txtText00.setBounds(320, 30, 150, 30); pnlBody.add(txtText00); this.lblTitle01.setText("密 码:"); this.lblTitle01.setBounds(230, 70, 80, 30); pnlBody.add(lblTitle01); txtPwd = new JPasswordField(); this.txtPwd.setBounds(320, 70, 150, 30); pnlBody.add(txtPwd); this.lblTitle02.setText("确认密码:"); this.lblTitle02.setBounds(230, 110, 80, 30); pnlBody.add(lblTitle02); txtPwd2 = new JPasswordField(); this.txtPwd2.setBounds(320, 110, 150, 30); pnlBody.add(txtPwd2); this.lblTitle03.setText("昵 称:"); this.lblTitle03.setBounds(230, 150, 80, 30); pnlBody.add(lblTitle03); this.txtText03.setBounds(320, 150, 150, 30); pnlBody.add(txtText03); this.lblTitle04.setText("邮 箱:"); this.lblTitle04.setBounds(230, 190, 80, 30); pnlBody.add(lblTitle04); this.txtText04.setBounds(320, 190, 150, 30); pnlBody.add(txtText04); this.lblTitle05.setText("用户类型:"); this.lblTitle05.setBounds(230, 230, 80, 30); pnlBody.add(lblTitle05); cboUserType = new JComboBox<KeyText>(); this.cboUserType.setBounds(320, 230, 150, 30); pnlBody.add(cboUserType); } public void editEvent() { } public void editLoad() { showUserType(); } @Override public void cancel_oper() { // TODO Auto-generated method stub this.dispose(); } @Override public void clear_oper() { // TODO Auto-generated method stub this.lblMsg.setText("提示:实现账号的添加。"); this.txtText00.setText(""); this.txtPwd.setText(""); this.txtPwd2.setText(""); this.txtText03.setText(""); this.txtText04.setText(""); this.txtText00.setText(""); cboUserType.getModel().setSelectedItem(new KeyText("","管理员")); } @Override public void confirm_oper() { // TODO Auto-generated method stub this.lblMsg.setText(""); //0.获取表用户输入数据 String userName = this.txtText00.getText(); String userPass = this.txtPwd.getText(); String userPass2 = this.txtPwd2.getText(); String nickName = this.txtText03.getText(); String email = this.txtText04.getText(); KeyText item = (KeyText) cboUserType.getModel().getSelectedItem(); String userType = item.getKey(); //1.为空性判断 String msg = ""; if(SysFun.isNullOrEmpty(userName)) { msg = "提示:"+"账号不能为空。"; this.lblMsg.setText(msg); return; } if(SysFun.isNullOrEmpty(userPass)) { msg = "提示:"+"密码不能为空。"; this.lblMsg.setText(msg); return; } if(SysFun.isNullOrEmpty(userPass2)) { msg = "提示:"+"确认密码不能为空。"; this.lblMsg.setText(msg); return; } if(SysFun.isNullOrEmpty(nickName)) { msg = "提示:"+"昵称不能为空。"; this.lblMsg.setText(msg); return; } if(SysFun.isNullOrEmpty(email)) { msg = "提示:"+"邮箱不能为空。"; this.lblMsg.setText(msg); return; } if(!userPass.equals(userPass2)) { msg = "提示:"+"两次密码不一致。"; this.lblMsg.setText(msg); return; } MemberService memberService = new MemberServiceImpl(); //3.业务判断:判断账号是否已存在。 Member existsItem = memberService.loadByName(userName); if(existsItem!=null) { msg = "提示:"+"账号已存在,请重新设置。"; this.lblMsg.setText(msg); return; } //7.准备添加到数据库 Member bean = new Member(); bean.setUserName(userName); bean.setUserPass(userPass); bean.setEmail(email); bean.setNickName(nickName); bean.setStatus(userType); bean.setCreateBy(1L); bean.setCreateOn(new java.util.Date()); bean.setUpdateBy(1L); bean.setUpdateOn(new java.util.Date()); //8.真正的添加 Long result = 0L; try { result = memberService.insert(bean); msg = "操作成功"; }catch(Exception ex) { msg = "操作失败。原因:"+ex.getMessage(); } this.lblMsg.setText(msg); if(result>0L) { msg = "提示:添加成功"; if(null != memberListFrm) { memberListFrm.search_oper(); } this.dispose(); } } public MemberListFrm memberListFrm = null; private JPasswordField txtPwd; private JPasswordField txtPwd2; private JComboBox<KeyText> cboUserType; private void showUserType() { List<KeyText> list = new ArrayList<KeyText>(); list.add(new KeyText("", "管理员")); list.add(new KeyText("Teacher", "教师 ")); list.add(new KeyText("Student", "学生 ")); //设置JComboBox对象的数据源 cboUserType.setModel(new KeyTextModel(list)); //设置JComboBox的数据源的当前选中的项目 cboUserType.getModel().setSelectedItem(new KeyText("")); } }
package edu.uc.ui.win.manager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.table.TableModel; import com.liuvei.common.FormatFun; import com.liuvei.common.SysFun; import com.liuvei.common.win.AInner; import com.liuvei.common.win.AInnerList; import com.liuvei.common.win.ATableModel; import com.liuvei.common.win.InnerFactory; import edu.uc.bean.Member; import edu.uc.service.MemberService; import edu.uc.service.impl.MemberServiceImpl; public class MemberListFrm extends AInnerList{ public MemberListFrm() { initFrm(); } public void initFrm() { editComponent(); editEvent(); editLoad(); } protected JMenuItem changePwdMenuItem = null; @Override public void createContextMenu() { super.createContextMenu(); changePwdMenuItem = new JMenuItem(); changePwdMenuItem.setText("重置密码"); changePwdMenuItem.setVisible(true); tblContextMenu.add(changePwdMenuItem); changePwdMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub changePwdMenuItem_click(e); } }); } public void changePwdMenuItem_click(ActionEvent e) { // TODO Auto-generated method stub Long pk = 0L; int index = this.tblObj.getSelectedRow(); if(index !=-1) { TableModel model = tblObj.getModel(); Object obj = model.getValueAt(index, 0); pk = Long.parseLong(""+obj); } MemberService memberService = new MemberServiceImpl(); Member bean = memberService.load(pk); if(null != bean) { Long result =0L; bean.setUserPass("123");//默认重置密码123 result = memberService.update(bean); if(result>0) { JOptionPane.showConfirmDialog(null,"重置成功。","提示", JOptionPane.DEFAULT_OPTION); search_oper(); }else { JOptionPane.showConfirmDialog(null,"重置失败。","提示", JOptionPane.DEFAULT_OPTION); } } } public void editComponent() { } public void editEvent() { } public void editLoad() { } @Override public void delete_oper(Object arg0) { // TODO Auto-generated method stub Long pk = 0L; int index = this.tblObj.getSelectedRow(); if(index !=-1) { TableModel model = tblObj.getModel(); Object obj = model.getValueAt(index, 0); pk = Long.parseLong(""+obj); } if(pk > 0) { MemberService memberService = new MemberServiceImpl(); Long result =0L; result = memberService.delete(pk); if(result>0) { JOptionPane.showConfirmDialog(null,"删除成功。","提示", JOptionPane.DEFAULT_OPTION); search_oper(); }else { JOptionPane.showConfirmDialog(null,"删除失败。","提示", JOptionPane.DEFAULT_OPTION); } } } public String modelName = "member"; @Override public void insert_oper() { // TODO Auto-generated method stub String vKeySuffix = modelName; String vClassFullName = MemberInsertFrm.class.getName(); String vKey = vClassFullName+":"+vKeySuffix+""; String vTitle = "用户管理"+"-添加"; InnerFactory.generalInner(modelName, vKey, vTitle, vClassFullName, mainFrm); //获取子窗体对象 AInner inner = InnerFactory.getInner(modelName, vKey, InnerFactory.getDesktop(mainFrm)); //子窗体转换后,传递主键,并加载数据 MemberInsertFrm updateFrm = (MemberInsertFrm)inner; updateFrm.memberListFrm = this; } @Override public void other_oper(Object arg0) { // TODO Auto-generated method stub } @Override public void search_oper() { // TODO Auto-generated method stub String txtKeyWords = this.txtKeywords.getText().trim(); //5.1初始化服务对象(可以作为属性) MemberService memberService = new MemberServiceImpl(); //5.2从DB中取得List集合数据 java.util.List<Member> list = null; if(SysFun.isNullOrEmpty(txtKeyWords)) { list = memberService.list(); } else { list = memberService.listByName(txtKeyWords); } //5.3将List集合数据传给【实体类表格模型】 ATableModel<Member> tableModel = null; tableModel = new ATableModel<Member>(list,6) { public String getTitle(int columnIndex) { if(columnIndex==0) { return "Id";//用户自定义 }else if(columnIndex == 1) { return "用户名称";//用户自定义 }else if(columnIndex== 2) { return "昵称";//用户自定义 }else if(columnIndex== 3) { return "Email";//用户自定义 }else if(columnIndex== 4) { return "状态";//用户自定义 }else if(columnIndex== 5) { return "创建时间";//用户自定义 } return "无"; } public Object getPropValue(Member bean,int columnIndex) { Member item = (Member) bean; if(columnIndex== 0) { return item.getUserId(); }else if(columnIndex== 1) { return item.getUserName(); }else if(columnIndex== 2) { return item.getNickName(); }else if(columnIndex== 3) { return item.getEmail(); }else if(columnIndex== 4) { return item.getStatus(); }else if(columnIndex== 5) { return FormatFun.format(item.getCreateOn(),FormatFun.FORMAT_DATETIME); } return null; } }; //5.4设置表格对象的数据模型 this.tblObj.setModel(tableModel); } @Override public void update_oper(Object arg0) { // TODO Auto-generated method stub Long pk = 0L; int index = this.tblObj.getSelectedRow(); if(index !=-1) { TableModel model = tblObj.getModel(); Object obj = model.getValueAt(index, 0); pk = Long.parseLong(""+obj); } if(pk > 0) { String vKeySuffix = modelName; String vClassFullName = MemberUpdateFrm.class.getName(); String vKey = vClassFullName+":"+vKeySuffix+""+pk; String vTitle = "用户管理"+"- 修改【pk="+pk+"】的记录"; //生成子窗体 InnerFactory.generalInner(modelName, vKey, vTitle, vClassFullName, mainFrm); //获取子窗体对象 AInner inner = InnerFactory.getInner(modelName, vKey, InnerFactory.getDesktop(mainFrm)); //子窗体转换后,传递主键,并加载数据 MemberUpdateFrm updateFrm = (MemberUpdateFrm)inner; updateFrm.memberListFrm = this; updateFrm.pk = pk; updateFrm.loadData(); } } }
package edu.uc.ui.win.manager; import java.util.ArrayList; import java.util.List; import javax.swing.JComboBox; import javax.swing.JPasswordField; import com.liuvei.common.SysFun; import com.liuvei.common.win.AInnerEdit; import com.liuvei.common.win.KeyText; import com.liuvei.common.win.KeyTextModel; import edu.uc.bean.Member; import edu.uc.service.MemberService; import edu.uc.service.impl.MemberServiceImpl; public class MemberUpdateFrm extends AInnerEdit{ public Long pk = 0L; public void loadData() { if(null!=pk && pk>0) { MemberService memberService = new MemberServiceImpl(); Member bean = memberService.load(pk); if(null!=bean) { txtText00.setText(bean.getUserName()); txtText03.setText(bean.getNickName()); txtText04.setText(bean.getEmail()); cboUserType.getModel().setSelectedItem(new KeyText(bean.getStatus())); cboUserType.repaint(); } } } public MemberUpdateFrm() { initFrm(); } public void initFrm() { editComponent(); editEvent(); editLoad(); } public void editComponent() { this.lblMsg.setText("提示:实现账号的修改。"); this.lblTitle00.setText("账 号:"); this.lblTitle00.setBounds(230, 30, 80, 30); pnlBody.add(lblTitle00); this.txtText00.setBounds(320, 30, 150, 30); pnlBody.add(txtText00); this.lblTitle03.setText("昵 称:"); this.lblTitle03.setBounds(230, 70, 80, 30); pnlBody.add(lblTitle03); this.txtText03.setBounds(320, 70, 150, 30); pnlBody.add(txtText03); this.lblTitle04.setText("邮 箱:"); this.lblTitle04.setBounds(230, 110, 80, 30); pnlBody.add(lblTitle04); this.txtText04.setBounds(320, 110, 150, 30); pnlBody.add(txtText04); this.lblTitle05.setText("用户类型:"); this.lblTitle05.setBounds(230, 150, 80, 30); pnlBody.add(lblTitle05); cboUserType = new JComboBox<KeyText>(); this.cboUserType.setBounds(320, 150, 150, 30); pnlBody.add(cboUserType); } public void editEvent() { } public void editLoad() { showUserType(); } @Override public void cancel_oper() { // TODO Auto-generated method stub this.dispose(); } @Override public void clear_oper() { // TODO Auto-generated method stub this.lblMsg.setText("提示:实现账号的修改。"); // this.txtText00.setText(""); // this.txtText03.setText(""); // this.txtText04.setText(""); // this.txtText00.setText(""); // cboUserType.getModel().setSelectedItem(new KeyText("","管理员")); loadData(); } @Override public void confirm_oper() { // TODO Auto-generated method stub this.lblMsg.setText(""); //0.获取表用户输入数据 String userName = this.txtText00.getText(); String nickName = this.txtText03.getText(); String email = this.txtText04.getText(); KeyText item = (KeyText) cboUserType.getModel().getSelectedItem(); String userType = item.getKey(); //1.为空性判断 String msg = ""; if(SysFun.isNullOrEmpty(userName)) { msg = "提示:"+"账号不能为空。"; this.lblMsg.setText(msg); return; } if(SysFun.isNullOrEmpty(nickName)) { msg = "提示:"+"昵称不能为空。"; this.lblMsg.setText(msg); return; } if(SysFun.isNullOrEmpty(email)) { msg = "提示:"+"邮箱不能为空。"; this.lblMsg.setText(msg); return; } MemberService memberService = new MemberServiceImpl(); //3.业务判断:判断账号是否已存在。 Member existsItem = memberService.loadByName(userName); if(existsItem!=null && existsItem.getUserId()!=pk) { msg = "提示:"+"账号已存在,请重新设置。"; this.lblMsg.setText(msg); return; } //7.准备修改到数据库 Member bean = memberService.load(pk); bean.setUserName(userName); bean.setEmail(email); bean.setNickName(nickName); bean.setStatus(userType); bean.setUpdateBy(1L); bean.setUpdateOn(new java.util.Date()); //8.真正的修改 Long result = 0L; try { result = memberService.update(bean); msg = "操作成功"; }catch(Exception ex) { msg = "操作失败。原因:"+ex.getMessage(); } if(result>0L) { msg = "修改成功"; } if(null != memberListFrm) { memberListFrm.search_oper(); } this.dispose(); } public MemberListFrm memberListFrm = null; private JComboBox<KeyText> cboUserType; private void showUserType() { List<KeyText> list = new ArrayList<KeyText>(); list.add(new KeyText("", "管理员")); list.add(new KeyText("Teacher", "教师 ")); list.add(new KeyText("Student", "学生 ")); //设置JComboBox对象的数据源 cboUserType.setModel(new KeyTextModel(list)); //设置JComboBox的数据源的当前选中的项目 cboUserType.getModel().setSelectedItem(new KeyText("")); } }
界面其实现在用不到(理解)
但是代码至少一遍,敲多了就慢慢了解,要查,要写博客,收获
英语很重要,认真
打基础,不要眼高手低
(上面的都是对我自己说的)
标签:art except tco 选中 子窗体 sts 实体 ane splay
原文地址:https://www.cnblogs.com/quenvpengyou/p/12872057.html