Exemplo n.º 1
0
  public PasswordDialog(final JFrame owner) {
    super(owner, "Login", true);
    setSize(280, 150);
    user = new JTextField(10);
    user.addActionListener(this);
    password = new JPasswordField(10);
    password.addActionListener(this);
    JPanel center = new JPanel();
    center.setLayout(new GridLayout(3, 2));
    center.add(new JLabel("Enter UserName:"******"Enter Password: "******"Submit");
    submitButton.setActionCommand("SUBMIT");
    submitButton.addActionListener(this);

    JButton helpButton = new JButton("Help");
    south.add(submitButton);
    south.add(helpButton);
    helpButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent aEvent) {
            JOptionPane.showMessageDialog(
                owner,
                "Your username and password are the same as those\n"
                    + "you use to access your O'Reilly School of Technology courses. \n");
          }
        });
    Container contentPane = getContentPane();
    contentPane.add(center, BorderLayout.CENTER);
    contentPane.add(south, BorderLayout.SOUTH);
  }
Exemplo n.º 2
0
  public AccesoSistema() {

    super("Ingreso Al Sistema");
    setSize(400, 200); // el tamaño de la venta
    setLocationRelativeTo(null); // es para que la pantalla aparezaca en el centro
    setLayout(null);
    setVisible(true); // para mostrar la ventana

    // esta parte de arriba es el constructor : es el que le premite crear componentes

    lblimagen.setIcon(getClass().getResource("/Imagenes/Escudo.png"));
    lblimagen.setBounds(270, 10, 120, 140);
    this.add(lblimagen);
    lblusuario = new JLabel("Usuario: ");
    lblclave = new JLabel("Contraseña: ");
    txtusuario = new JTextField("");
    txtclave = new JPasswordField("");
    btningresar = new JButton("Ingresar");
    txtusuario.addActionListener(this);
    txtclave.addActionListener(this);
    btningresar.addActionListener(this); // Ponemos A Escuchar El Boton
    btnsalir = new JButton("Salir");
    btnsalir.addActionListener(this);
    lblusuario.setBounds(20, 20, 80, 25);
    lblclave.setBounds(20, 60, 80, 25);
    txtusuario.setBounds(130, 20, 120, 25);
    txtclave.setBounds(130, 60, 120, 25);
    btningresar.setBounds(20, 100, 120, 25);
    btnsalir.setBounds(150, 100, 120, 25);
    lblusuario.setForeground(new Color(0, 0, 0));
    // lblusuario.setBorder(BorderFactory.createLineBorder(Color.yellow, WIDTH));//sirve para
    // mostrar el tamaño del lbl
    txtusuario.setBackground(Color.WHITE); // este es para darle color a la caja de texto
    txtusuario.setToolTipText("Ingrese Su Usuario"); // sirve para mostrar mensajes emergentes
    this.add(lblusuario);
    this.add(lblclave);
    this.add(txtusuario);
    this.add(txtclave);
    this.add(btningresar);
    this.add(btnsalir);
    this.repaint();
  }
  /**
   * Called by constructors to initialize the dialog.
   *
   * @since ostermillerutils 1.00.00
   */
  @Override
  protected void dialogInit() {

    if (labels == null) {
      setLocale(Locale.getDefault());
    }

    name = new JTextField("", 20);
    pass = new JPasswordField("", 20);
    okButton = new JButton(labels.getString("dialog.ok"));
    cancelButton = new JButton(labels.getString("dialog.cancel"));
    nameLabel = new JLabel(labels.getString("dialog.name") + " ");
    passLabel = new JLabel(labels.getString("dialog.pass") + " ");

    super.dialogInit();

    KeyListener keyListener =
        (new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE
                || (e.getSource() == cancelButton && e.getKeyCode() == KeyEvent.VK_ENTER)) {
              pressed_OK = false;
              PasswordDialog.this.setVisible(false);
            }
            if (e.getSource() == okButton && e.getKeyCode() == KeyEvent.VK_ENTER) {
              pressed_OK = true;
              PasswordDialog.this.setVisible(false);
            }
          }
        });
    addKeyListener(keyListener);

    ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            if (source == name) {
              // the user pressed enter in the name field.
              name.transferFocus();
            } else {
              // other actions close the dialog.
              pressed_OK = (source == pass || source == okButton);
              PasswordDialog.this.setVisible(false);
            }
          }
        };

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    c.insets.top = 5;
    c.insets.bottom = 5;
    JPanel pane = new JPanel(gridbag);
    pane.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20));
    c.anchor = GridBagConstraints.EAST;
    gridbag.setConstraints(nameLabel, c);
    pane.add(nameLabel);

    gridbag.setConstraints(name, c);
    name.addActionListener(actionListener);
    name.addKeyListener(keyListener);
    pane.add(name);

    c.gridy = 1;
    gridbag.setConstraints(passLabel, c);
    pane.add(passLabel);

    gridbag.setConstraints(pass, c);
    pass.addActionListener(actionListener);
    pass.addKeyListener(keyListener);
    pane.add(pass);

    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.CENTER;
    JPanel panel = new JPanel();
    okButton.addActionListener(actionListener);
    okButton.addKeyListener(keyListener);
    panel.add(okButton);
    cancelButton.addActionListener(actionListener);
    cancelButton.addKeyListener(keyListener);
    panel.add(cancelButton);
    gridbag.setConstraints(panel, c);
    pane.add(panel);

    getContentPane().add(pane);

    pack();
  }
Exemplo n.º 4
0
  /**
   * Sets window contents to login interface. Handles the user interactions.
   *
   * @author Zombori Dániel
   * @param newParent AdWindow that displays LoginGUI
   * @param container Method adds elements to this container
   */
  public void show(final AdWindow newParent, Container container) {
    parent = newParent;
    if (!created) {

      ActionListener al =
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (DataBase.login(
                      textFieldName.getText(),
                      Secret.encrypt(new String(textFieldPassword.getPassword())))
                  == null) {
                // bejelentkezés sikertelen
                labelStatus.setText("Rossz felhasználónév vagy jelszó");
              } else {
                // bejelentkezve
                labelStatus.setText("Sikeres bejelentkezés");
                UserGUI.resetSingleton();
                parent.refreshGUI(UserGUI.getSingleton());
              }
              textFieldPassword.setText("");
            }
          };

      // grid
      panelGrid = new JPanel();
      panelGrid.setLayout(new GridLayout(6, 1));

      labelEmpty = new JLabel();

      // név és jelszó
      textFieldName = new JTextField("Bejelentkezési név", 30);
      textFieldPassword = new JPasswordField("12345", 30);

      textFieldName.addActionListener(al);
      textFieldPassword.addActionListener(al);

      // gombok
      btnLogin = new JButton("Bejelentkezés");
      btnRegister = new JButton("Regisztráció");

      btnLogin.addActionListener(al);

      btnRegister.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              parent.refreshGUI(RegisterGUI.getSingleton(), true);
            }
          });

      created = true;
    }
    labelStatus = new JLabel("Adja meg adatait", JLabel.CENTER);
    textFieldPassword.setText("");

    // grid
    panelGrid.add(labelStatus);
    panelGrid.add(textFieldName);
    panelGrid.add(textFieldPassword);
    panelGrid.add(btnLogin);
    panelGrid.add(labelEmpty);
    panelGrid.add(btnRegister);

    // container
    container.add(panelGrid);
  }