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); } }
解决 无用评论 打赏 举报
悬赏问题
- ¥30 STM32 INMP441无法读取数据
- ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
- ¥15 用visualstudio2022创建vue项目后无法启动
- ¥15 x趋于0时tanx-sinx极限可以拆开算吗
- ¥500 把面具戴到人脸上,请大家贡献智慧
- ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
- ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
- ¥30 c#打开word开启修订并实时显示批注
- ¥15 如何解决ldsc的这条报错/index error
- ¥15 VS2022+WDK驱动开发环境