Esempio n. 1
0
 /**
  * Este método permite atualizar todos os campos de texto para a linguagem definida na interface
  * inicial, com o auxílio da classe Language.java.
  *
  * @author João Machado
  */
 public void UpdateLanguage() {
   Lang = Language.getInstance().GetLanguage();
   this.UsernameLabel.setText(java.util.ResourceBundle.getBundle(Lang).getString("UsernameLabel"));
   this.PasswordLabel.setText(java.util.ResourceBundle.getBundle(Lang).getString("PasswordLabel"));
   this.CancelButton.setText(java.util.ResourceBundle.getBundle(Lang).getString("CancelButton"));
   this.ConfimPasswordLabel.setText(
       java.util.ResourceBundle.getBundle(Lang).getString("ConfirmPasswordLabel"));
   this.ConfirmButton.setText(java.util.ResourceBundle.getBundle(Lang).getString("ConfirmButton"));
   this.ConfirmEmailLabel.setText(
       java.util.ResourceBundle.getBundle(Lang).getString("ConfirmEmailLabel"));
   this.RegisterUserLabel.setText(
       java.util.ResourceBundle.getBundle(Lang).getString("RegisterUserLabel"));
 }
Esempio n. 2
0
/**
 * Este interface permite aos utilizadores introduzirem campos necessário ao registo.
 *
 * @author Andre
 */
public class UIRegister extends javax.swing.JFrame {
  public String Lang = Language.getInstance().GetLanguage();
  /** Cria instancia da classe UIRegister */
  public UIRegister() {
    initComponents();
    setLocationRelativeTo(null);
    this.xPassword.setVisible(false);
    this.xName.setVisible(false);
    this.xEmail.setVisible(false);
    this.ErrorLabel.setText("");
    jPanel1.setOpaque(false);
  }
  /*
   * Set genérico
   */
  public void enableConfirmButton() {
    this.ConfirmButton.setEnabled(true);
  }
  /*
   * Set genérico
   */
  public void setxEmail() {
    this.xEmail.setVisible(true);
  }
  /*
   * Set genérico
   */
  public void setxName() {
    this.xName.setVisible(true);
  }
  /*
   * Set genérico
   */
  public void setxPassword() {
    this.xPassword.setVisible(true);
  }
  /*
   * Set genérico
   */
  public void setErrorLabel(String text) {
    this.ErrorLabel.setText(text);
  }
  /*
   * Set genérico
   */
  public void setClearFields() {
    this.ErrorLabel.setText("");
    this.EmailField.setText("");
    this.UsernameField.setText("");
    this.PasswordField.setText("");
    this.ConfirmPasswordField.setText("");
    this.ConfirmEmailField.setText("");
  }

  /**
   * Este método permite atualizar todos os campos de texto para a linguagem definida na interface
   * inicial, com o auxílio da classe Language.java.
   *
   * @author João Machado
   */
  public void UpdateLanguage() {
    Lang = Language.getInstance().GetLanguage();
    this.UsernameLabel.setText(java.util.ResourceBundle.getBundle(Lang).getString("UsernameLabel"));
    this.PasswordLabel.setText(java.util.ResourceBundle.getBundle(Lang).getString("PasswordLabel"));
    this.CancelButton.setText(java.util.ResourceBundle.getBundle(Lang).getString("CancelButton"));
    this.ConfimPasswordLabel.setText(
        java.util.ResourceBundle.getBundle(Lang).getString("ConfirmPasswordLabel"));
    this.ConfirmButton.setText(java.util.ResourceBundle.getBundle(Lang).getString("ConfirmButton"));
    this.ConfirmEmailLabel.setText(
        java.util.ResourceBundle.getBundle(Lang).getString("ConfirmEmailLabel"));
    this.RegisterUserLabel.setText(
        java.util.ResourceBundle.getBundle(Lang).getString("RegisterUserLabel"));
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    ConfirmButton = new javax.swing.JButton();
    CancelButton = new javax.swing.JButton();
    RegisterUserLabel = new javax.swing.JLabel();
    jPanel1 = new javax.swing.JPanel();
    UsernameField = new javax.swing.JTextField();
    PasswordField = new javax.swing.JPasswordField();
    ConfirmPasswordField = new javax.swing.JPasswordField();
    EmailField = new javax.swing.JTextField();
    ConfirmEmailField = new javax.swing.JTextField();
    ConfirmEmailLabel = new javax.swing.JLabel();
    EmailLabel = new javax.swing.JLabel();
    ConfimPasswordLabel = new javax.swing.JLabel();
    UsernameLabel = new javax.swing.JLabel();
    PasswordLabel = new javax.swing.JLabel();
    xEmail = new javax.swing.JLabel();
    xPassword = new javax.swing.JLabel();
    xName = new javax.swing.JLabel();
    ErrorLabel = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    java.util.ResourceBundle bundle =
        java.util.ResourceBundle.getBundle("resources/Portugues_pt_PT_EURO"); // NOI18N
    setTitle(bundle.getString("AppTitle")); // NOI18N
    setResizable(false);
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    ConfirmButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    ConfirmButton.setText(bundle.getString("ConfirmButton")); // NOI18N
    ConfirmButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ConfirmButtonActionPerformed(evt);
          }
        });
    getContentPane()
        .add(ConfirmButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(246, 444, 171, 55));

    CancelButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    CancelButton.setText(bundle.getString("CancelButton")); // NOI18N
    CancelButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            CancelButtonActionPerformed(evt);
          }
        });
    getContentPane()
        .add(CancelButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(454, 444, 165, 55));

    RegisterUserLabel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
    RegisterUserLabel.setText(bundle.getString("RegisterUserLabel")); // NOI18N
    getContentPane()
        .add(RegisterUserLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(318, 60, -1, -1));

    UsernameField.setAlignmentY(0.0F);
    UsernameField.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    PasswordField.setAlignmentY(0.0F);
    PasswordField.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    PasswordField.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            PasswordFieldActionPerformed(evt);
          }
        });

    ConfirmPasswordField.setAlignmentY(0.0F);
    ConfirmPasswordField.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    EmailField.setAlignmentY(0.0F);
    EmailField.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    ConfirmEmailField.setAlignmentY(0.0F);
    ConfirmEmailField.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    ConfirmEmailLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    ConfirmEmailLabel.setText(bundle.getString("ConfirmEmailLabel")); // NOI18N
    ConfirmEmailLabel.setAlignmentY(0.0F);

    EmailLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    EmailLabel.setText("E-Mail:");
    EmailLabel.setAlignmentY(0.0F);

    ConfimPasswordLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    ConfimPasswordLabel.setText(bundle.getString("ConfirmPasswordLabel")); // NOI18N
    ConfimPasswordLabel.setAlignmentY(0.0F);

    UsernameLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    UsernameLabel.setText(bundle.getString("UsernameLabel")); // NOI18N
    UsernameLabel.setAlignmentY(0.0F);
    UsernameLabel.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseEntered(java.awt.event.MouseEvent evt) {
            UsernameLabelMouseEntered(evt);
          }
        });

    PasswordLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    PasswordLabel.setText("Password:"******"/resources/redcross.png"))); // NOI18N

    xPassword.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/resources/redcross.png"))); // NOI18N

    xName.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/resources/redcross.png"))); // NOI18N

    ErrorLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    ErrorLabel.setText("ERROR TEXT FIELD HERE...");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        jPanel1Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(ConfirmEmailLabel)
                                            .addComponent(EmailLabel)
                                            .addComponent(ConfimPasswordLabel))
                                    .addGap(17, 17, 17))
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        jPanel1Layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                UsernameLabel,
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(
                                                PasswordLabel,
                                                javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addGap(18, 18, 18)))
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        PasswordField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        335,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(xPassword))
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        UsernameField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        335,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(xName))
                            .addComponent(
                                ConfirmPasswordField,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                335,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        EmailField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        335,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(xEmail))
                            .addGroup(
                                jPanel1Layout
                                    .createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(
                                        ErrorLabel,
                                        javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                    .addComponent(
                                        ConfirmEmailField,
                                        javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        335,
                                        Short.MAX_VALUE)))));
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addGap(32, 32, 32)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(
                                jPanel1Layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(
                                        UsernameField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        32,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(UsernameLabel))
                            .addComponent(
                                xName,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                32,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(
                                jPanel1Layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(
                                        PasswordField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        31,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(PasswordLabel))
                            .addComponent(xPassword))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                ConfirmPasswordField,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                31,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ConfimPasswordLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(
                                jPanel1Layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(
                                        EmailField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(EmailLabel))
                            .addComponent(
                                xEmail,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                34,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                ConfirmEmailField,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                34,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ConfirmEmailLabel))
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                    .addComponent(ErrorLabel)
                    .addContainerGap()));

    getContentPane()
        .add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(114, 122, -1, -1));

    jLabel1.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/resources/background.jpg"))); // NOI18N
    getContentPane()
        .add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 860, 550));

    pack();
  } // </editor-fold>//GEN-END:initComponents

  private void PasswordFieldActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_PasswordFieldActionPerformed
    // TODO add your handling code here:

  } // GEN-LAST:event_PasswordFieldActionPerformed

  private void CancelButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_CancelButtonActionPerformed
    // TODO add your handling code here:
    this.setVisible(false);
    ClientStart.uiinitial.UISetVisible();
  } // GEN-LAST:event_CancelButtonActionPerformed

  private void ConfirmButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_ConfirmButtonActionPerformed

    String username = UsernameField.getText();
    char[] password = PasswordField.getPassword();
    char[] passwordConfirm = ConfirmPasswordField.getPassword();
    String email = EmailField.getText();
    String emailConfirm = ConfirmEmailField.getText();
    String pass = new String(password);
    String pConfirm = new String(passwordConfirm);
    MD5Pwd enc = new MD5Pwd();
    String passEnc;

    xEmail.setVisible(false);
    xName.setVisible(false);
    xPassword.setVisible(false);

    passEnc = enc.encode(username, pass);

    if (ValidateMail.isValidEmailAddress(email)) {

      if (email.equals(emailConfirm)) {

        if (!"".equals(username)) {

          if (pass.equals(pConfirm) && (!"".equals(pass))) {

            try {
              ComCliente com = ComCliente.getInstance();
              com.registar(username, passEnc, email);
              this.ConfirmButton.setEnabled(false);

            } catch (Exception e) {
              System.out.println("Accept failed: 4444");
              System.exit(-1);
            }

          } else {

            this.ErrorLabel.setText(
                java.util.ResourceBundle.getBundle(Lang).getString("PasswordConfirmError"));
            this.xPassword.setVisible(true);
            this.PasswordField.setText("");
            this.ConfirmPasswordField.setText("");
          }

        } else {
          this.ErrorLabel.setText(
              java.util.ResourceBundle.getBundle(Lang).getString("InsertUsername"));
          this.xName.setVisible(true);
        }
      } else {

        this.ErrorLabel.setText(
            java.util.ResourceBundle.getBundle(Lang).getString("EmailConfirmationError"));
        this.EmailField.setText("");
        this.ConfirmEmailField.setText("");
        this.xEmail.setVisible(true);
      }
    } else {
      this.ErrorLabel.setText(java.util.ResourceBundle.getBundle(Lang).getString("InvalidEmail"));
      this.EmailField.setText("");
      this.ConfirmEmailField.setText("");
      this.xEmail.setVisible(true);
    }
  } // GEN-LAST:event_ConfirmButtonActionPerformed

  private void UsernameLabelMouseEntered(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_UsernameLabelMouseEntered
    // TODO add your handling code here:
  } // GEN-LAST:event_UsernameLabelMouseEntered

  /** @param args the command line arguments */
  public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    // <editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info :
          javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException ex) {
      java.util.logging.Logger.getLogger(UIRegister.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      java.util.logging.Logger.getLogger(UIRegister.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      java.util.logging.Logger.getLogger(UIRegister.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(UIRegister.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    }
    // </editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            new UIRegister().setVisible(true);
          }
        });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton CancelButton;
  private javax.swing.JLabel ConfimPasswordLabel;
  private javax.swing.JButton ConfirmButton;
  private javax.swing.JTextField ConfirmEmailField;
  private javax.swing.JLabel ConfirmEmailLabel;
  private javax.swing.JPasswordField ConfirmPasswordField;
  private javax.swing.JTextField EmailField;
  private javax.swing.JLabel EmailLabel;
  private javax.swing.JLabel ErrorLabel;
  private javax.swing.JPasswordField PasswordField;
  private javax.swing.JLabel PasswordLabel;
  private javax.swing.JLabel RegisterUserLabel;
  private javax.swing.JTextField UsernameField;
  private javax.swing.JLabel UsernameLabel;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JLabel xEmail;
  private javax.swing.JLabel xName;
  private javax.swing.JLabel xPassword;
  // End of variables declaration//GEN-END:variables
}