/Parafia/src/gui/panels/LoginDialog.java

https://github.com/dasiu166/parafia · Java · 116 lines · 91 code · 19 blank · 6 comment · 2 complexity · 90fc646e170ca517b5739704906eefe1 MD5 · raw file

  1. package gui.panels;
  2. import javax.swing.JButton;
  3. import javax.swing.JDialog;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPasswordField;
  7. import javax.swing.JTextField;
  8. import javax.swing.SwingConstants;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.FocusAdapter;
  12. import java.awt.event.FocusEvent;
  13. import java.awt.event.ComponentAdapter;
  14. import java.awt.event.ComponentEvent;
  15. import javax.swing.ImageIcon;
  16. public class LoginDialog extends JDialog implements ActionListener{
  17. /**
  18. *
  19. */
  20. private static final long serialVersionUID = 1L;
  21. private JTextField tLogin;
  22. private JPasswordField pwdPassword;
  23. private JButton bOK, bCansel;
  24. private boolean okData = false;
  25. /**
  26. * Create the dialog.
  27. */
  28. public LoginDialog(JFrame owner) {
  29. super(owner, "Wprowadzanie hasła", true);
  30. addComponentListener(new ComponentAdapter() {
  31. @Override
  32. public void componentShown(ComponentEvent arg0) {
  33. okData = false;
  34. }
  35. });
  36. setResizable(false);
  37. setBounds(100, 100, 300, 220);
  38. getContentPane().setLayout(null);
  39. tLogin = new JTextField();
  40. tLogin.setText("");
  41. tLogin.setBounds(117, 38, 110, 23);
  42. tLogin.setColumns(10);
  43. getContentPane().add(tLogin);
  44. pwdPassword = new JPasswordField();
  45. pwdPassword.setText("");
  46. pwdPassword.setToolTipText("");
  47. pwdPassword.setBounds(117, 67, 110, 23);
  48. getContentPane().add(pwdPassword);
  49. JLabel lblLogin = new JLabel("Login:");
  50. lblLogin.setBounds(61, 41, 46, 14);
  51. lblLogin.setHorizontalAlignment(SwingConstants.RIGHT);
  52. getContentPane().add(lblLogin);
  53. JLabel lblPassword = new JLabel("Has\u0142o:");
  54. lblPassword.setBounds(61, 72, 46, 14);
  55. lblPassword.setHorizontalAlignment(SwingConstants.RIGHT);
  56. getContentPane().add(lblPassword);
  57. bOK = new JButton("Zaloguj");
  58. bOK.setIcon(new ImageIcon(LoginDialog.class.getResource("/icons/Accept-icon.png")));
  59. bOK.setBounds(40, 114, 97, 28);
  60. bOK.setActionCommand("OK");
  61. getContentPane().add(bOK);
  62. getRootPane().setDefaultButton(bOK);
  63. bOK.addActionListener(this);
  64. bCansel = new JButton("Anuluj");
  65. bCansel.setIcon(new ImageIcon(LoginDialog.class.getResource("/icons/Alcancel-icon.png")));
  66. bCansel.setBounds(162, 114, 97, 28);
  67. bCansel.setActionCommand("Cancel");
  68. getContentPane().add(bCansel);
  69. bCansel.addActionListener(this);
  70. }
  71. @Override
  72. public void actionPerformed(ActionEvent e) {
  73. Object z = e.getSource();
  74. if(z == bOK){
  75. okData = true;
  76. }else{
  77. okData = false;
  78. }
  79. setVisible(false);
  80. }
  81. public String getLogin(){
  82. return tLogin.getText();
  83. }
  84. public String getPassword(){
  85. return new String(pwdPassword.getPassword());
  86. }
  87. public boolean isOK(){
  88. return okData;
  89. }
  90. public void setFocus(){
  91. tLogin.requestFocusInWindow();
  92. }
  93. private void setLoginData(String login, String password){
  94. tLogin.setText(login);
  95. pwdPassword.setText(password);
  96. }
  97. }