Skip to content

Instantly share code, notes, and snippets.

@HashRaygoza
Created February 13, 2020 00:29
Show Gist options
  • Select an option

  • Save HashRaygoza/a72a75bed001bc7f61ee383d84c183aa to your computer and use it in GitHub Desktop.

Select an option

Save HashRaygoza/a72a75bed001bc7f61ee383d84c183aa to your computer and use it in GitHub Desktop.
Manejador de eventos de documento
package com.hash.databaseio.doclistener;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
*
* @author draygoza
*/
public class CuentaCaracteres implements DocumentListener, Runnable {
private final JPasswordField campoPassword;
static private final int DATA_LENGTH = 80;
public CuentaCaracteres(JPasswordField c) {
campoPassword = c;
}
@Override
public void insertUpdate(DocumentEvent e) {
String texto = new String(campoPassword.getPassword());
if(texto.length() == CuentaCaracteres.DATA_LENGTH) {
SwingUtilities.invokeLater(this);
}
}
@Override
public void removeUpdate(DocumentEvent e) {
}
@Override
public void changedUpdate(DocumentEvent e) {
}
@Override
public void run() {
campoPassword.requestFocus();
JOptionPane.showMessageDialog(campoPassword, "TODOS LOS DATOS LEIDOS");
campoPassword.setText("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment