Java 如何在inputDialog中键入时隐藏文本 if(e.getSource()==credLimit){//用户更改信用额度的事件处理 字符串输入=JOptionPane.showInputDialog(null,“输入密码”); setEchoChar('*');
这将隐藏您输入的文本Java 如何在inputDialog中键入时隐藏文本 if(e.getSource()==credLimit){//用户更改信用额度的事件处理 字符串输入=JOptionPane.showInputDialog(null,“输入密码”); setEchoChar('*');,java,user-interface,input,dialog,Java,User Interface,Input,Dialog,这将隐藏您输入的文本 if(e.getSource() == credLimit){ // event handling for user to change credit limit String input = JOptionPane.showInputDialog(null, "Enter Password"); input.setEchoChar('*'); <<-----here is what I have tried if(input.equal
if(e.getSource() == credLimit){ // event handling for user to change credit limit
String input = JOptionPane.showInputDialog(null, "Enter Password");
input.setEchoChar('*'); <<-----here is what I have tried
if(input.equals(password)) { // password check for credit limit
double credLimitTotal = Double.parseDouble(changeCredLimit.getText());
JOptionPane.showMessageDialog(null, currentCreditCard.changeCreditLimit(credLimitTotal));
changeCredLimit.setText("");
}
}
您不能在
输入对话框中直接隐藏字符。您可以使用默认情况下隐藏字符的创建自己的对话框。请尝试以下代码:
<input type="password" name="txtPassword" placeholder="Enter Password"/>
用于更改键入时显示给用户的字符。要隐藏文本框中的文本,您需要像这样使用JPassword
Box box = Box.createHorizontalBox();
JLabel jl = new JLabel("Password: ");
box.add(jl);
JPasswordField jpf = new JPasswordField(24);
box.add(jpf);
int button = JOptionPane.showConfirmDialog(null, box, "Enter your password", JOptionPane.OK_CANCEL_OPTION);
if (button == JOptionPane.OK_OPTION) {
char[] input = jpf.getPassword();
if(input.equals(password)) {
...
}
}
这里是到的链接,以了解更多详细信息
这是HTML,不是Java
passwordField = new JPasswordField(10);
passwordField.setActionCommand(OK);