package gui; import java.awt.BorderLayout; import javax.swing.*; /** * Allows the user to log in and starts new shell in the case of success. * * @author Jan Horký */ public class Login { public Login() { } public boolean exec() { LoginPanel login = new LoginPanel(); if (JOptionPane.showConfirmDialog(null, login, "Login", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) return true; else return false; } @SuppressWarnings("serial") private class LoginPanel extends JPanel { private JLabel userJLabel, passJLabel; private JTextField userJTextField; private JPasswordField passJPasswordField; /** Creates a new instance of LoginJPanel */ public LoginPanel() { initialize(); } public String getLogin() { return (userJTextField.getText()); } public String getPassword() { return (new String(passJPasswordField.getPassword())); } private void initialize() { this.setLayout(new BorderLayout()); userJLabel = new JLabel("Username: "); passJLabel = new JLabel("Password: "); userJTextField = new JTextField("default_user", 10); passJPasswordField = new JPasswordField("password", 10); JPanel leftJPanel = new JPanel(new BorderLayout()); leftJPanel.add(userJLabel, BorderLayout.NORTH); leftJPanel.add(passJLabel, BorderLayout.SOUTH); JPanel rightJPanel = new JPanel(new BorderLayout()); rightJPanel.add(userJTextField, BorderLayout.NORTH); rightJPanel.add(passJPasswordField, BorderLayout.SOUTH); this.add(leftJPanel, BorderLayout.WEST); this.add(rightJPanel, BorderLayout.EAST); } } }