java编写的具有注册功能的桌面程序,当两次密码输入不一致时,清除密码框的内容,但是不清除已经输入的用户名等其他信息,请问各位大佬这个功能该如何实现?
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);
}
}
不知道 我知道qt 是调用ui指向需要清理的.调用clear c艹的也是