("对不起,非法的用户名和密码!!!");
this.clear();//清空输入窗口
}
}
else if(e.getSource()==jbArray[1])
{//事件源为
注册按钮
if(user.equals("")||pwd.equals(""))
{
jlArray[2].setText("用户名和密码都不得为空!!!");
this.clear();
}
else
{
sql="select uid from user where uid='"+user+"'";
if(DButil.isExist(sql))
{
jlArray[2].setText("对不起,用户名已存在!!!");
this.clear();
}
else
{
sql="insert into user values('"+user+"','"+pwd+"')";
if(DButil.update(sql)>0)
{
jlArray[2].setText("恭喜您!!!注册成功,请登陆");
}
}
}
}
else if(e.getSource()==jbArray[2])//修改密码的监听
{
if(user.equals("")||pwd.equals(""))
{
jlArray[2].setText("修改密码先输入正确的用户名和密码!!!");
this.clear();
}
else if(DButil.check(user,pwd))
{
String pass
word=JOptionPane.showInputDialog(this,"修改密码:","请输入新密码",
JOptionPane.PLAIN_MESSAGE);
if(password==null||password.equals(""))
{
JOptionPane.showMessageDialog(this,"密码不得为空!!!","错误",
JOptionPane.WARNING_MESSAGE);
}
else
{
sql="update user set pwd='"+password+"' where uid='"+user+"'";//更新密码的SQL
if(DButil.update(sql)>0)
{
this.clear();
jlArray[2].setText("恭喜您!!!密码修改成功,请用新密码登陆");
}
}
}
else
{
JOptionPane.showMessageDialog(this,"用户名或者密码错误!!!","错误",
JOptionPane.WARNING_MESSAGE);
this.clear();
}
}
else if(e.getSource()==jbArray[3])//删除用户
{
if(DButil.check(user,pwd))
{//密码和用户都对的情况
int yn=JOptionPane.showConfirmDialog(this,"是否删除?","删除",
JOptionPane.YES_NO_OPTION);
if(yn==JOptionPane.YES_OPTION)
{
int count=DButil.delUser(user);
jlArray[2].setText("用户"+user+"删除成功"+"共删除了"+count+"个联系人");
this.clear();//清空输入文本框
}
}
else
{//密码和用户名不匹配
jlArray[2].setText("对不起,非法的用户名和密码!!!");
this.clear();
}
}
}
public static void main(String []args)
{
new Login();
}
}
MainFrame.java
package tongxunlu;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.io.*;
public class MainFrame extends JFrame implements ActionListener,ItemListener
{
private String uname=null;
private String perNameBefor=null;
private String perGroupBefor=null;
private boolean searchByName=true;//true则默认为按查找
private boolean isInsert=false;
Image image=Toolkit.getDefaultToolkit().getImage("img/txl.jpg");//得到图标对象
Icon icon = new ImageIcon(image);
private JPanel jps=new JPanel();//界面上半部分的JPanel容器
private JButton jba=new JButton("添加");
private JButton jbs=new JButton("查找");
private JTextField jtfs=new JTextField();//按给出信息查找联系人信息
private JRadioButton jrbxm=new JRadioButton("按查找",true);
private JRadioButton jrbbh=new JRadioButton("按编号查找");
private ButtonGroup bg=new ButtonGroup();
private JPanel jpbr=new JPanel();
//界面左下的树 创建树模型 指定节点"联系人"为根节点
Defa