PLANE_23
-树先生-
采纳率0%
2021-03-04 18:50

java编写的桌面程序怎么清除密码框中的内容

java编写的具有注册功能的桌面程序,当两次密码输入不一致时,清除密码框的内容,但是不清除已经输入的用户名等其他信息,请问各位大佬这个功能该如何实现?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • weixin_45485578 超级套娃 1月前

    不知道 我知道qt 是调用ui指向需要清理的.调用clear   c艹的也是

    点赞 评论 复制链接分享
  • allway2 allway2 1月前
    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);
    	}
    }
    
    点赞 评论 复制链接分享