Mascara en JDialog
Publicado por Carlos (7 intervenciones) el 15/03/2007 06:01:08
Quiero poner una mascara en el JTextField "Campo1", pero no me deja de ninguna forma. Busque en internet y no me permite, en momentos me saca el campo o sino directamente no funciona la mascara. Agradecere quien sepa solucionarlo. Aca le mando la clase que quiero colocar la mascara. Saludos. Carlos.
package Cliente.CrearUsuario;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import ComunRMI.IControlBoleta;
import ComunRMI.IControlUsuario;
import ComunRMI.Dto.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JWindow;
import javax.swing.text.MaskFormatter;
import Cliente.MensajesPorPantalla.*;
import com.sun.jdori.common.sco.Vector;
import java.awt.Font;
import java.awt.Toolkit;
public class CrearUsuario implements ActionListener{
private JDialog jDialog = null;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField Campo1 = null;
private JPasswordField jPasswordField = null;
private JPasswordField jPasswordField1 = null;
private JButton jButton = null;
private JButton JButtonVolver = null;
private IControlUsuario ControlUsuario;
private JPanel jContentPane1 = null;
public CrearUsuario(IControlUsuario Control2){
ControlUsuario = Control2;
this.getJDialog();
this.getJDialog().setModal(true);
this.getJDialog().setVisible(true);
}
public void InsertarUsuario1(String nombre, String pass) {
try{
UsuarioDto p = new UsuarioDto();
p.setNombre(nombre);
p.setPassword(pass);
this.ControlUsuario.insertarUsuario(p);
}catch(Exception ex){}
}
/**
* This method initializes jDialog
*
* @return javax.swing.JDialog
*/
private JDialog getJDialog() {
if (jDialog == null) {
jDialog = new JDialog();
jDialog.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height);
jDialog.setResizable(false);
jDialog.setLocation(0,-29);
jDialog.setTitle("Crear Usuario");
jDialog.setContentPane(getJContentPane());
}
return jDialog;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setSize(110,80);
jLabel.setLocation(450,300);
jLabel.setFont(new Font("Dialog", java.awt.Font.BOLD,22));
jLabel.setText("Nombre");
jLabel1 = new JLabel();
jLabel1.setSize(110,80);
jLabel1.setLocation(450,400);
jLabel1.setFont(new Font("Dialog", java.awt.Font.BOLD,22));
jLabel1.setText("Clave");
jLabel2 = new JLabel();
jLabel2.setSize(170,80);
jLabel2.setLocation(450,500);
jLabel2.setFont(new Font("Dialog", java.awt.Font.BOLD,22));
jLabel2.setText("Reescribir Clave");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJPasswordField1(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(getButtonVolver(),null);
}
return jContentPane;
}
private JButton getButtonVolver(){
if (JButtonVolver == null) {
JButtonVolver = new JButton();
JButtonVolver.setLocation(1100,910);
JButtonVolver.setSize(100,35);
JButtonVolver.setText("VOLVER");
JButtonVolver.setToolTipText("Regresar al menu principal");
JButtonVolver.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jDialog.dispose();
}});
}
return JButtonVolver;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (Campo1 == null) {
Campo1 = new JTextField();
Campo1.setSize(200,25);
Campo1.setLocation(650,330);
Campo1.setToolTipText("Nombre por el cual seras conocido");
}
return Campo1;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setSize(200,25);
jPasswordField.setLocation(650,430);
jPasswordField.setToolTipText("Contraseña de tu cuenta");
}
return jPasswordField;
}
/**
* This method initializes jPasswordField1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField1() {
if (jPasswordField1 == null) {
jPasswordField1 = new JPasswordField();
jPasswordField1.setSize(200,25);
jPasswordField1.setLocation(650,530);
jPasswordField1.setToolTipText("Reingreso de la contraseña de tu cuenta");
}
return jPasswordField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setSize(150,30);
jButton.setLocation(600,600);
jButton.setText("Crear Usuario");
jButton.setFont(new Font("Dialog", java.awt.Font.BOLD,14));
jButton.setToolTipText("Crea tu cuenta de usuario");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
if (( Campo1.getText().length()>0 )&
(jPasswordField.getPassword().length>0) &
(jPasswordField1.getPassword().length>0) &
(jPasswordField.getText().equals(jPasswordField1.getText())))
{
try{
if (!ExisteUsuario(ControlUsuario.RecuperarUsuarios())){
InsertarUsuario1(Campo1.getText(), jPasswordField.getText());
MensajesPorPantalla k = new MensajesPorPantalla(3);
jDialog.dispose();
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
else {
MensajesPorPantalla k = new MensajesPorPantalla(2);
}
}});
}
return jButton;
}
private boolean ExisteUsuario(java.util.Vector vector){
int i = 0;
boolean b = false;
if (vector.size()>0){
while((i+1 <= vector.size()) & (!b))
{
UsuarioDto s = (UsuarioDto)vector.elementAt(i);
if ((s.getNombre().equals(Campo1.getText()))){
b = true;
MensajesPorPantalla k = new MensajesPorPantalla(1);
}
i = i + 1;
}
}
return b;
};
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
package Cliente.CrearUsuario;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import ComunRMI.IControlBoleta;
import ComunRMI.IControlUsuario;
import ComunRMI.Dto.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JWindow;
import javax.swing.text.MaskFormatter;
import Cliente.MensajesPorPantalla.*;
import com.sun.jdori.common.sco.Vector;
import java.awt.Font;
import java.awt.Toolkit;
public class CrearUsuario implements ActionListener{
private JDialog jDialog = null;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField Campo1 = null;
private JPasswordField jPasswordField = null;
private JPasswordField jPasswordField1 = null;
private JButton jButton = null;
private JButton JButtonVolver = null;
private IControlUsuario ControlUsuario;
private JPanel jContentPane1 = null;
public CrearUsuario(IControlUsuario Control2){
ControlUsuario = Control2;
this.getJDialog();
this.getJDialog().setModal(true);
this.getJDialog().setVisible(true);
}
public void InsertarUsuario1(String nombre, String pass) {
try{
UsuarioDto p = new UsuarioDto();
p.setNombre(nombre);
p.setPassword(pass);
this.ControlUsuario.insertarUsuario(p);
}catch(Exception ex){}
}
/**
* This method initializes jDialog
*
* @return javax.swing.JDialog
*/
private JDialog getJDialog() {
if (jDialog == null) {
jDialog = new JDialog();
jDialog.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height);
jDialog.setResizable(false);
jDialog.setLocation(0,-29);
jDialog.setTitle("Crear Usuario");
jDialog.setContentPane(getJContentPane());
}
return jDialog;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setSize(110,80);
jLabel.setLocation(450,300);
jLabel.setFont(new Font("Dialog", java.awt.Font.BOLD,22));
jLabel.setText("Nombre");
jLabel1 = new JLabel();
jLabel1.setSize(110,80);
jLabel1.setLocation(450,400);
jLabel1.setFont(new Font("Dialog", java.awt.Font.BOLD,22));
jLabel1.setText("Clave");
jLabel2 = new JLabel();
jLabel2.setSize(170,80);
jLabel2.setLocation(450,500);
jLabel2.setFont(new Font("Dialog", java.awt.Font.BOLD,22));
jLabel2.setText("Reescribir Clave");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJPasswordField1(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(getButtonVolver(),null);
}
return jContentPane;
}
private JButton getButtonVolver(){
if (JButtonVolver == null) {
JButtonVolver = new JButton();
JButtonVolver.setLocation(1100,910);
JButtonVolver.setSize(100,35);
JButtonVolver.setText("VOLVER");
JButtonVolver.setToolTipText("Regresar al menu principal");
JButtonVolver.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jDialog.dispose();
}});
}
return JButtonVolver;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (Campo1 == null) {
Campo1 = new JTextField();
Campo1.setSize(200,25);
Campo1.setLocation(650,330);
Campo1.setToolTipText("Nombre por el cual seras conocido");
}
return Campo1;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setSize(200,25);
jPasswordField.setLocation(650,430);
jPasswordField.setToolTipText("Contraseña de tu cuenta");
}
return jPasswordField;
}
/**
* This method initializes jPasswordField1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField1() {
if (jPasswordField1 == null) {
jPasswordField1 = new JPasswordField();
jPasswordField1.setSize(200,25);
jPasswordField1.setLocation(650,530);
jPasswordField1.setToolTipText("Reingreso de la contraseña de tu cuenta");
}
return jPasswordField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setSize(150,30);
jButton.setLocation(600,600);
jButton.setText("Crear Usuario");
jButton.setFont(new Font("Dialog", java.awt.Font.BOLD,14));
jButton.setToolTipText("Crea tu cuenta de usuario");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
if (( Campo1.getText().length()>0 )&
(jPasswordField.getPassword().length>0) &
(jPasswordField1.getPassword().length>0) &
(jPasswordField.getText().equals(jPasswordField1.getText())))
{
try{
if (!ExisteUsuario(ControlUsuario.RecuperarUsuarios())){
InsertarUsuario1(Campo1.getText(), jPasswordField.getText());
MensajesPorPantalla k = new MensajesPorPantalla(3);
jDialog.dispose();
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
else {
MensajesPorPantalla k = new MensajesPorPantalla(2);
}
}});
}
return jButton;
}
private boolean ExisteUsuario(java.util.Vector vector){
int i = 0;
boolean b = false;
if (vector.size()>0){
while((i+1 <= vector.size()) & (!b))
{
UsuarioDto s = (UsuarioDto)vector.elementAt(i);
if ((s.getNombre().equals(Campo1.getText()))){
b = true;
MensajesPorPantalla k = new MensajesPorPantalla(1);
}
i = i + 1;
}
}
return b;
};
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
Valora esta pregunta


0