//此类是找回密码 package com.view; import java.awt.Color; /** * 找回密码 * @author wu2xin * */ public class InTo_Forget extends JFrame implements ActionListener{ /** * 成员变量 */ private static final long serialVersionUID = 1L; private JPanel contentPane; private JPanel panel; private JLabel nameLab,alertLab,alertImg; private JTextField nameTex; private JTextField emailTex; private JButton delBut; private JScrollPane scrollPane; private JLabel alert; private JTextArea textArea; private JButton blackBut; private JCheckBox nameCheck,emailCheck; private JButton lookBtu; private JLabel topImage; /** * new 出来新窗口 */ public static void main(String[] args) { InTo_Forget frame = new InTo_Forget(); frame.setVisible(true); } /** * 构造初始化 */ public InTo_Forget() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setUndecorated(true);//去掉窗口的装饰 this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);////设置为简单对话窗口 this.setTitle("找回密码"); this.setSize(694, 498); this.setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); alertImg=new JLabel(new ImageIcon("image/search1.gif")); alertImg.setBounds(0, 21, 60, 45); contentPane.add(alertImg); alertLab =new JLabel("找回密码"); alertLab.setFont(new Font("楷体", Font.BOLD, 20)); alertLab.setLocation(65, 21); alertLab.setSize(113, 30); contentPane.add(alertLab); topImage = new JLabel(new ImageIcon("image/找回密码插景图.jpg")); topImage.setBounds(376, 0, 307, 114); contentPane.add(topImage); /** *操作 面板 */ panel = new JPanel(); panel.setOpaque(false);//透明 TitledBorder tb=new TitledBorder("欢迎找回密码"); tb.setTitleFont(new Font("陈代明硬笔体", Font.PLAIN, 20)); tb.setTitleColor(Color.blue); panel.setBorder(tb);//在Jpanel上打几个标题 panel.setBounds(0, 104, 684, 298); contentPane.add(panel); panel.setLayout(null); nameCheck = new JCheckBox("按用户名"); nameCheck.setBounds(3, 33, 82, 30); nameCheck.setOpaque(false);//透明 nameCheck.addActionListener(this);//监听1 panel.add(nameCheck); emailCheck = new JCheckBox("按邮箱"); emailCheck.setBounds(3, 105, 82, 30); emailCheck.setOpaque(false);//透明 emailCheck.addActionListener(this);//监听1 panel.add(emailCheck); nameLab = new JLabel("用户名:"); nameLab.setForeground(Color.BLUE); nameLab.setFont(new Font("楷体", Font.BOLD, 16)); nameLab.setHorizontalAlignment(SwingConstants.RIGHT); nameLab.setBounds(27, 69, 73, 30); panel.add(nameLab); nameTex = new JTextField(); nameTex.setBackground(Color.WHITE); nameTex.setEditable(false); nameTex.setBounds(110, 68, 123, 30); panel.add(nameTex); nameTex.setColumns(10); JLabel emailLab = new JLabel("邮箱:"); emailLab.setForeground(Color.BLUE); emailLab.setFont(new Font("楷体", Font.BOLD, 16)); emailLab.setHorizontalAlignment(SwingConstants.RIGHT); emailLab.setBounds(27, 141, 73, 30); panel.add(emailLab); emailTex = new JTextField(); emailTex.setBackground(Color.WHITE); emailTex.setEditable(false); emailTex.setColumns(10); emailTex.setBounds(110, 141, 123, 30); panel.add(emailTex); lookBtu= new JButton("查询"); lookBtu.setBounds(27, 226, 71, 30); lookBtu.addActionListener(this);//监听1 panel.add(lookBtu); delBut = new JButton("清空"); delBut.setBounds(162, 226, 71, 30); delBut.addActionListener(this);//监听1 panel.add(delBut); scrollPane = new JScrollPane(); scrollPane.setBounds(322, 44, 354, 231); panel.add(scrollPane); textArea = new JTextArea(); scrollPane.setViewportView(textArea); alert = new JLabel("信息提示:"); alert.setHorizontalAlignment(SwingConstants.RIGHT); alert.setForeground(Color.BLACK); alert.setFont(new Font("楷体", Font.PLAIN, 16)); alert.setBounds(263, 10, 82, 30); panel.add(alert); blackBut = new JButton("返回主页"); blackBut.setBounds(574, 412, 86, 30); blackBut.addActionListener(this);//监听1 contentPane.add(blackBut); JLabel topImg = new JLabel(new ImageIcon("image/forget.jpg")); topImg.setBounds(0, 0, 686, 498); contentPane.add(topImg); this.setVisible(true);//可见 } /////////////////////////////////////////////////////////////注册监听器1(普通事件) @Override public void actionPerformed(ActionEvent de) { // TODO Auto-generated method stub String id=nameTex.getText(); //String email=emailTex.getText(); AdminModel model=new AdminModel(); if(de.getSource()==nameCheck){//用户名单选 if(nameCheck.isSelected()){ nameTex.setEditable(true); emailTex.setEditable(false); emailCheck.setSelected(false); }else{ nameTex.setEditable(false); } }else if(de.getSource()==emailCheck){//email 单选 if(emailCheck.isSelected()){ nameTex.setEditable(false); nameCheck.setSelected(false); emailTex.setEditable(true); } }else if(de.getSource()==lookBtu){//查询 if(StringUtil.isNotNull(id)){ AdminPoJo pojo=model.getAdmin(Integer.parseInt(id)); if(pojo!=null){ textArea.setText(id+",找回成功!\n\t"+pojo.getName()+"你好,你的密码是:"+pojo.getPassword()); }else{ textArea.setText("对不起,查找失败,没有"+id+"该账号"); } }else{ JOptionPane.showMessageDialog(null, "请选择查询条件"); } }else if(de.getSource()==delBut){//撤销 nameTex.setText(""); emailTex.setText(""); textArea.setText(""); }else if(de.getSource()==blackBut){//返回登录主界面 new InTo(); this.dispose(); } } }