2 * PanelIniciarSesion.java
4 * Created on 5 de mayo de 2008, 11:32
9 import javax
.swing
.event
.DocumentEvent
;
10 import javax
.swing
.event
.DocumentListener
;
16 public class PanelIniciarSesion
extends javax
.swing
.JPanel
{
17 private String nombre
;
18 private String password
;
19 private boolean anonimo
;
21 private class DocumentListenerTextos
implements DocumentListener
24 public void insertUpdate(DocumentEvent e
) {
25 actualizarEstadoBotonInicio();
28 public void removeUpdate(DocumentEvent e
) {
29 actualizarEstadoBotonInicio();
32 public void changedUpdate(DocumentEvent e
) {
33 actualizarEstadoBotonInicio();
37 private DocumentListenerTextos listenerTextos
= new DocumentListenerTextos();
38 /** Creates new form PanelIniciarSesion */
39 public PanelIniciarSesion() {
41 mensajeEstado
.setVisible(false);
42 nombreUsuario
.getDocument().addDocumentListener(listenerTextos
);
43 passwordUsuario
.getDocument().addDocumentListener(listenerTextos
);
46 public boolean isAnonimo() {
50 public String
getNombre() {
54 public String
getPassword() {
60 /** This method is called from within the constructor to
61 * initialize the form.
62 * WARNING: Do NOT modify this code. The content of this method is
63 * always regenerated by the Form Editor.
65 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
66 private void initComponents() {
68 etiquetaPassword
= new javax
.swing
.JLabel();
69 etiquetaUsuario
= new javax
.swing
.JLabel();
70 passwordUsuario
= new javax
.swing
.JPasswordField();
71 nombreUsuario
= new javax
.swing
.JTextField();
72 botonIniciarSesion
= new javax
.swing
.JButton();
73 mensajeEstado
= new javax
.swing
.JLabel();
74 inicioSesionAnonimo
= new javax
.swing
.JCheckBox();
76 etiquetaPassword
.setText("Clave");
78 etiquetaUsuario
.setText("Usuario");
80 nombreUsuario
.setName(""); // NOI18N
82 botonIniciarSesion
.setEnabled(false);
83 botonIniciarSesion
.setLabel("Iniciar Sesión");
84 botonIniciarSesion
.addActionListener(new java
.awt
.event
.ActionListener() {
85 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
86 botonIniciarSesionActionPerformed(evt
);
90 mensajeEstado
.setForeground(new java
.awt
.Color(0, 51, 204));
91 mensajeEstado
.setHorizontalAlignment(javax
.swing
.SwingConstants
.CENTER
);
92 mensajeEstado
.setText("Iniciando sesión...");
94 inicioSesionAnonimo
.setText("Usuario anonimo");
95 inicioSesionAnonimo
.setHorizontalAlignment(javax
.swing
.SwingConstants
.TRAILING
);
96 inicioSesionAnonimo
.addActionListener(new java
.awt
.event
.ActionListener() {
97 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
98 inicioSesionAnonimoActionPerformed(evt
);
102 org
.jdesktop
.layout
.GroupLayout layout
= new org
.jdesktop
.layout
.GroupLayout(this);
103 this.setLayout(layout
);
104 layout
.setHorizontalGroup(
105 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
106 .add(org
.jdesktop
.layout
.GroupLayout
.TRAILING
, layout
.createSequentialGroup()
107 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
108 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
110 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
, false)
111 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, etiquetaPassword
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
112 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, etiquetaUsuario
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
))
113 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
114 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
115 .add(passwordUsuario
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 289, Short
.MAX_VALUE
)
116 .add(nombreUsuario
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 289, Short
.MAX_VALUE
)))
117 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
119 .add(botonIniciarSesion
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 273, Short
.MAX_VALUE
)
121 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
123 .add(mensajeEstado
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 349, Short
.MAX_VALUE
))
124 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
126 .add(inicioSesionAnonimo
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 353, Short
.MAX_VALUE
)))
129 layout
.setVerticalGroup(
130 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
131 .add(layout
.createSequentialGroup()
133 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
134 .add(layout
.createSequentialGroup()
135 .add(etiquetaUsuario
)
136 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
137 .add(etiquetaPassword
))
138 .add(layout
.createSequentialGroup()
139 .add(nombreUsuario
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
140 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
141 .add(passwordUsuario
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)))
142 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
143 .add(inicioSesionAnonimo
)
144 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
145 .add(botonIniciarSesion
)
146 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
147 .add(mensajeEstado
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, 10, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
148 .addContainerGap(29, Short
.MAX_VALUE
))
150 }// </editor-fold>//GEN-END:initComponents
152 private void botonIniciarSesionActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_botonIniciarSesionActionPerformed
153 mensajeEstado
.setText("Iniciando sesión...");
154 mensajeEstado
.setVisible(true);
155 }//GEN-LAST:event_botonIniciarSesionActionPerformed
156 private void actualizarEstadoBotonInicio()
158 botonIniciarSesion
.setEnabled(nombreUsuario
.getText().length() >0 && passwordUsuario
.getPassword().length
> 0);
160 private void inicioSesionAnonimoActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_inicioSesionAnonimoActionPerformed
161 boolean enabled
= inicioSesionAnonimo
.isSelected();
162 nombreUsuario
.setEnabled(!enabled
);
163 passwordUsuario
.setEnabled(!enabled
);
164 botonIniciarSesion
.setEnabled(enabled
|| (nombreUsuario
.getText().length() >0 && passwordUsuario
.getPassword().length
> 0));
165 }//GEN-LAST:event_inicioSesionAnonimoActionPerformed
168 // Variables declaration - do not modify//GEN-BEGIN:variables
169 private javax
.swing
.JButton botonIniciarSesion
;
170 private javax
.swing
.JLabel etiquetaPassword
;
171 private javax
.swing
.JLabel etiquetaUsuario
;
172 private javax
.swing
.JCheckBox inicioSesionAnonimo
;
173 private javax
.swing
.JLabel mensajeEstado
;
174 private javax
.swing
.JTextField nombreUsuario
;
175 private javax
.swing
.JPasswordField passwordUsuario
;
176 // End of variables declaration//GEN-END:variables