密码域控件的简单应用
2013-10-20 19:34
344 查看
应用场景:用户注册,密码输入
功能界面:
窗口界面设计部分代码:
判断部分代码:
本文出自 “好记性,不如烂笔头” 博客,请务必保留此出处http://lixiyu.blog.51cto.com/4136883/1312333
功能界面:
窗口界面设计部分代码:
public class JPasswordFieldTest extends JFrame { /** * */ private static final long serialVersionUID = 8633179606754193326L; private JPanel contentPane; private JPasswordField passwordField1; private JPasswordField passwordField2; /** * Launch the application. */ public static void main(String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { try { JPasswordFieldTest frame = new JPasswordFieldTest(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public JPasswordFieldTest() { setTitle("\u5BC6\u7801\u57DF\u63A7\u4EF6\u7B80\u5355\u5E94\u7528"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 200); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new GridLayout(3, 1, 5, 5)); JPanel passwordPanel1 = new JPanel(); contentPane.add(passwordPanel1); JLabel label1 = new JLabel("\u8F93\u5165\u5BC6\u7801\uFF1A"); label1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); passwordPanel1.add(label1); passwordField1 = new JPasswordField(); passwordField1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); passwordField1.setColumns(20); passwordPanel1.add(passwordField1); JPanel passwordPanel2 = new JPanel(); contentPane.add(passwordPanel2); JLabel label2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A"); label2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); passwordPanel2.add(label2); passwordField2 = new JPasswordField(); passwordField2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); passwordField2.setColumns(20); passwordPanel2.add(passwordField2); JPanel buttonPanel = new JPanel(); contentPane.add(buttonPanel); JButton submitButton = new JButton("\u63D0\u4EA4"); submitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_submitButton_actionPerformed(e); } }); submitButton.setFont(new Font("微软雅黑", Font.PLAIN, 18)); buttonPanel.add(submitButton); }
判断部分代码:
protected void do_submitButton_actionPerformed(ActionEvent e) { char[] password1 = passwordField1.getPassword(); char[] password2 = passwordField2.getPassword(); if (password1.length < 6) { JOptionPane.showMessageDialog(this, "密码长度小于6位", "", JOptionPane.WARNING_MESSAGE); } else if (!Arrays.equals(password1, password2)) { JOptionPane.showMessageDialog(this, "两次密码不同", "", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(this, "两次密码相同", "", JOptionPane.INFORMATION_MESSAGE); } }
本文出自 “好记性,不如烂笔头” 博客,请务必保留此出处http://lixiyu.blog.51cto.com/4136883/1312333
相关文章推荐
- 【jquery模仿net控件】初步GridView模型实现,及其简单应用
- Linkbutton控件在项目中的简单应用
- WebBrowser控件的简单应用
- ASP.NET Cookies简单应用 记住用户名和密码
- Android编程基础之简单Button事件响应综合提示控件Toast应用示例
- android之视频播放控件VideoView简单应用
- datagrid的几点简单应用,功能包括radio的单选,checkbox的多选,鼠标移动到行上颜色变深,链接传递多参数等功能。这里radio和checkbox都使用的是HTML控件。
- WebBrowser控件的简单应用
- Linkbutton控件在项目中的简单应用
- 转载牛人的ASP.NET Cookies简单应用 记住用户名和密码 收藏
- ASP.NET Cookies简单应用 记住用户名和密码
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- iOS开发UI高级—10使用picker View控件完成一个简单的选餐应用
- ASP.NET Cookies简单应用 记住用户名和密码
- 简单应用js操作asp.net控件
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- jquery demo - jquery ui 日期控件简单应用
- aspnetajax UpdatePanel控件简单应用
- WebBrowser控件的简单应用2