【Java精品源码栏目提醒】:本文主要为网学会员提供“【精品】Java实现通讯录系统全部源码 - 其它资料”,希望对需要【精品】Java实现通讯录系统全部源码 - 其它资料网友有所帮助,学习一下!
Java 实现《通讯录》 软件测试.094 谭 又 中 2011/09/25 共 37 页)1登陆界面:源码:package sourcesimport java.awt.import java.awt.event.import javax.swing.public class LoginForm extends JFrame implements ActionListener //声明组件 private JPanel jpanel1new JPanel //声明面板容器 private JLabel arrayJLabelnew JLabelquot用户名:quotnew JLabelquot密 码:quotnew JLabelquotquot //声明包含三个标签的标签数组 private JTextField userNameJTextFieldnew JTextField //声明用户名文本域 private JPasswordField passwordJPasswordFieldnew JPasswordField //声明密码输入域 private JButton arrayJButtonnew JButtonquot登 录quotnew JButtonquot注 册quot //声明包含两个按钮数组 //构造函数 public LoginForm //设置窗体相关属性 //设置标题栏显示图标 Image icon2Toolkit.getDefaultToolkit.getImagequotimagesico.gifquot this.setIconImageicon2 //设置窗口标题 this.setTitlequot--登 录--quot //设置窗口不可拖动大小 this.setResizablefalse //设置窗口大小 this.setSize350300 //获取屏幕尺寸 Dimension screenSizeToolkit.getDefaultToolkit.getScreenSize int screenWidthscreenSize.width int srceenHeightscreenSize.height //设置窗口居于屏幕中央 setLocationscreenWidth-getWidth/2srceenHeight-getHeight/2 //设置组件的相关属性 //设置面板容器的布局策略为空 jpanel1.setLayoutnull //设置面板容器背景色 jpanel1.setBackgroundColor.WHITE //利用循环添加标签和按钮 forint i0ilt2i 2 //设置2个标签和2个按钮的位置及大小 arrayJLabeli.setBounds65 164i35 80 26 arrayJButtoni.setBounds60i135 235 90 26 //设置2个标签和两个按钮的文本颜色 arrayJLabeli.setForegroundColor.RED arrayJButtoni.setForegroundColor.RED //设置2个标签和两个按钮的字体 arrayJLabeli.setFontnew Fontquot宋体quotFont.PLAIN14 arrayJButtoni.setFontnew Fontquot宋体quotFont.PLAIN15 //将2个标签和2个按钮添加到面板容器 jpanel1.addarrayJLabeli jpanel1.addarrayJButtoni //为按钮添加动作事件监听器 arrayJButtoni.addActionListenerthis //设置文本域和密码框的最大输入字符量 userNameJTextField.setColumns15 passwordJPasswordField.setColumns16 //设置文本域和密码框的位置及大小 userNameJTextField.setBounds115 161 160 30 passwordJPasswordField.setBounds115 198 160 30 //设置密码输入回显字符 passwordJPasswordField.setEchoChar //设置文本域和密码框的文本颜色 userNameJTextField.setForegroundColor.RED passwordJPasswordField.setForegroundColor.RED //设置文本域和密码框的字体 userNameJTextField.setFontnew Fontquot宋体quotFont.BOLD16 passwordJPasswordField.setFontnew Fontquot宋体quotFont.BOLD16 //定义一个图标对象,用于显示登陆界面图像 ImageIcon icon1new ImageIconquotimagestxl_1.jpgquot //设置图像 arrayJLabel2.setIconicon1 //设置标签位置及尺寸 arrayJLabel2.setBounds00350158 //将文本域和密码框添加到面板容器 jpanel1.addarrayJLabel2 jpanel1.adduserNameJTextField jpanel1.addpasswordJPasswordField //为文本域和密码框添加事件监听器 userNameJTextField.addActionListenerthis passwordJPasswordField.addActionListenerthis //将面板容器添加到内容窗格 this.addjpanel1 //为窗口添加关闭响应事件 this.addWindowListenernew WindowAdapter public void windowClosingWindowEvent e System.exit0 //显示窗体 this.setVisibletrue//定义一个公共方法,清空文本域内容,并定位焦点到文本域public void userNameClear 3 //清空文本域内容 userNameJTextField.setTextquotquot //文本域获得焦点 userNameJTextField.requestFocus //定义一个公共方法,清空密码框内容,并定位焦点到密码框 public void passwordClear //清空密码框内容 passwordJPasswordField.setTextquotquot //密码框获得焦点 passwordJPasswordField.requestFocus //Override //声明此方法为重写方法 //实现ActionListener接口的方法,以实现对事件的监听处理 public void actionPerformedActionEvent e //定义变量用于调用DBOperate类的方法的实参传递 String useruserNameJTextField.getText.toString.trim //用户名变量 String pwdString.valueOfpasswordJPasswordField.getPassword //密码变量 String sqlquotquot //SQL查询语句变量 //如果事件源是文本域输入框,则进行相应操作 ife.getSourceuserNameJTextField //让焦点转移到密码框 passwordJPasswordField.requestFocus //如果事件源是登录按钮或者是在输入密码完毕后点击了回车按钮,则进行相应操作 else ife.getSourcearrayJButton0e.getSourcepasswordJPasswordField //判断输入是否合法 ifuser.equalsquotquot //提示输入不合法 JOptionPane.showMessageDialogthis quot用户名输入不合法quot quot系统提示quotJOptionPane.INFORMATION_MESSAGE //文本域获得焦点 userNameJTextField.requestFocus //该句可防止用户名和密码均为空一次性弹出2个对话框 return ifpwd.equalsquotquot //提示输入不合法 JOptionPane.showMessageDialogthis quot密码输入不合法quot quot系统提示quotJOptionPane.INFORMATION_MESSAGE //密码框获得焦点 passwordJPasswordField.requestFocus return else //调用DBOperate类的方法进行判断,用户名及密码是否匹配 ifDBOperate.checkuserpwd //登录成功,显示主窗体并传递登录‘用户名’作为实参 MainFrame mainframenew MainFrameuser mainframe.setVisibletrue //释放登录窗口 this.dispose else //登录失败,提示用户名或密码出错 JOptionPane.showMessageDialognull quot用户名或密码有误,n请检查是否无误再进行登录quot quot系统提示quotJOptionPane.ERROR_MESSAGE //清空密码框 this.passwordClear 4 //清空文本域 this.userNameClear return //如果事件源是注册按钮则进行相应操作 else ife.getSourcearrayJButton1 //判断文本域是否为空 ifuser.equalsquotquot //提示输入不合法 JOptionPane.showMessageDialogthis quot用户名不能为空quot quot系统提示quotJOptionPane.INFORMATION_MESSAGE //清除文本域内容 this.userNameClear //文本域获得焦点 userNameJTextField.requestFocus //该句可防止用户名和密码均为空一次性弹出2个对话框 return //判断密码框是否为空 else ifpwd.equalsquotquot //提示输入不合法 JOptionPane.showMessageDialogthis quot密码不能为空quot quot系统提示quotJOptionPane.INFORMATION_MESSAGE //清除密码框内容 this.passwordClear //密码框获得焦点 passwordJPasswordField.requestFocus return //判断注册用户是否存在 else //判断注册的用户是否已经存在 sqlquotSELECT UserName FROM User WHERE UserNamequotuserquotquot ifDBOperate.isExistsql //注册用户已经存在,进行相应提示 JOptionPane.showMessageDialogthis quot对不起,注册失败!n该用户已经存在quot quot系统提示quotJOptionPane.INFORMATION_MESSAGE //清除密码框内容 this.passwordClear //清除文本域内容 this.userNameClear return else //尝试捕获异常 try //满足条件执行注册操作 sqlquotINSERT INTO User VALUESquotuserquotquotpwdquotquot ifDBOperate.updatesqlgt0 //提示用户注册成功 JOptionPane.showMessageDialogthis quot恭喜你n注册成功!quot quot系统提示quotJOptionPane.INFORMATION_MESSAGE return catchException ex //打印出错误原因 ex.printStackTrace 5 //主方法 public static void mainString args new LoginForm//创建登陆窗体 主界面:其他界面:系统菜单: 解锁:源码:package sourcesimport 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 ActionListenerItemListener 6 //定义锁定状态变量 private String lockStatequotquot //定义背景颜色对象 private Color bgColornew Color201237201 //定义字体颜色对象 private Color foreColornew Color6112038 //定义字体对象 private Font fontnew Fontquot宋体quotFont.PLAIN15// 声明菜单组件 //菜单栏 private JMenuBar menubarnew JMenuBar //菜单 private JMenu systemMenunew JMenuquot系统Squot private JMenu helpMenunew JMenuquot帮助Hquot //系统菜单项 private JMenuItem alterPasswordItemnew JMenuItemquot修改密码NquotN private JMenuItem delUserItemnew JMenuItemquot删除用户DquotD private JMenuItem lockItemnew JMenuItemquot锁定LquotL private JMenuItem cancelItemnew JMenuItemquot注销WquotW private JMenuItem exitItemnew JMenuItemquot退出XquotX //帮助菜单项 private JMenuItem helpItemnew JMenuItemquot帮助HquotH private JMenuItem aboutItemnew JMenuItemquot关于AquotA private String usernull//当前用户的名字 private String perNameBefornull//编辑的时候之前的名字 private String perGroupBefornull//编辑的时候修改之前的分组 private boolean searchByNametrue//true则默认为按姓名查找 private boolean isInsertfalse//是否为添加默认为否 Image imageToolkit.getDefaultToolkit.getImagequotimagestxl_2.jpgquot//得到图标对象 Icon icon new ImageIconimage private JPanel jpsnew JPanel//界面上半部分的JPanel容器 private JButton jbanew JButtonquot添加quot private JButton jbsnew JButtonquot查找quot private JTextField jtfsnew JTextField//按给出信息查找联系人信息 //选择查找方式的单选按钮 private JRadioButton jrbxmnew JRadioButtonquot按姓名查找quottrue private JRadioButton jrbbhnew JRadioButtonquot按编号查找quot private ButtonGroup bgnew ButtonGroup//单选按钮组 private JPanel jpbrnew JPanel//单选按钮面板 //界面左下的树 创建树模型 指定节点quot联系人quot为根节点 DefaultMutableTreeNode root new DefaultMutableTreeNodenew NodeValuequot联系人quot0 DefaultTreeModel dtmnew DefaultTreeModelroot private JTree jtznew JTree//界面下半部分左边的JTree private JScrollPane jspznew JScrollPanejtz//JTree的滚动条 private DefaultTreeCellRenderer dtcrnew DefaultTreeCellRenderer//树节点的绘制器 private JPanel jpynew JPanel//界面下半部分右边界面,布局管理器为卡片布局 private JPanel jpyInfonew JPanel//右侧显示个人信息的面板 //界面下半部分右边的JPanel容器的个人信息栏目里的控件 private JLabel jlInfonew JLabelquot用户编号:quotnew JLabelquot姓名:quot new JLabelquot性别:quotnew JLabelquot年龄:quot new JLabelquot电话号码:quotnew JLabelquotEmail:quot new JLabelquot所属组:quotnew JLabelquot更改照片:quot new JLabelquot邮编:quotnew JLabelquot地址:quot new JLabelquot添加相片quotnew JLabelquotquot private JButton jbInfonew JButtonquot编辑quotnew JButtonquot保存quot new JButtonquot删除quotnew JButtonquot浏览quot new JButtonquot添加分组quotnew JButtonquot删除分组quot new JButtonquot浏览quotnew JButtonquot上传quot new JButtonquot删除quot //初始默认的一些分组 private String strquot朋友quotquot同事quotquot家庭quotquot重要人士quotquot其他quot 7private JComboBox jcbnew JComboBoxstr//分组下拉列表控件private JLabel jlPhotonew JLabel//显示图像的JLabel控件private JTextField jtfInfonew JTextField10private JTextField jtfPhotonew JTextField//添加照片到相册的路径private JFileChooser jfcPicnew JFileChooserquotf:quot//上传图像的文件选择器private JFileChooser jfcPhonew JFileChooserquotf:quot//上传照片的文件选择器//性别部分private JRadioButton jrbMalenew JRadioButtonquot男quottrueprivate JRadioButton jrbFemalenew JRadioButtonquot女quotprivate ButtonGroup bgGendernew ButtonGroupprivate JPanel jpGendernew JPanel//单选按钮面板private JPanel jpyviewnew JPanel//右侧显示多幅照片的面板private JScrollPane jspyviewnew JScrollPanejpyview//滚动条private JLabel jlDetailnew JLabel//右侧显示一幅图片的标签private JScrollPane jspydetailnew JScrollPanejlDetail//显示一幅图片标签的滚动条private JLabel jlNoPicnew JLabelquot您还没有为该联系人添加照片quot//没有照片的显示JLabel//图片加载进度条部分private JPanel jpProgressnew JPanel//右侧显示图片加载进度的面板private JLabel jlProgressnew JLabelquot预览图片.上一篇:计算器JAVA源代码