java编写的具有注册功能的桌面程序,当两次密码输入不一致时,清除密码框的内容,但是不清除已经输入的用户名等其他信息,请问各位大佬这个功能该如何实现?
2条回答 默认 最新
- allway2 2021-03-04 19:14关注
import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class PasswordText extends JFrame { private JPanel contentPane; private JPasswordField passwordField; private JTextField textField; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { PasswordText frame = new PasswordText(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public PasswordText() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); passwordField = new JPasswordField(); passwordField.setBounds(121, 118, 152, 21); contentPane.add(passwordField); textField = new JTextField(); textField.setBounds(119, 87, 154, 21); contentPane.add(textField); textField.setColumns(10); JLabel lblNewLabel = new JLabel("Username"); lblNewLabel.setBounds(20, 90, 54, 15); contentPane.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("Password"); lblNewLabel_1.setBounds(20, 121, 54, 15); contentPane.add(lblNewLabel_1); JButton btnNewButton = new JButton("Login"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!passwordField.getText().equals("password")) { passwordField.setText(""); } } }); btnNewButton.setBounds(180, 174, 93, 23); contentPane.add(btnNewButton); } }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 Arduino红外遥控代码有问题
- ¥15 数值计算离散正交多项式
- ¥30 数值计算均差系数编程
- ¥15 redis-full-check比较 两个集群的数据出错
- ¥15 Matlab编程问题
- ¥15 训练的多模态特征融合模型准确度很低怎么办
- ¥15 kylin启动报错log4j类冲突
- ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
- ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
- ¥15 onvif+openssl,vs2022编译openssl64