Guest User

Untitled

a guest
Nov 23rd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4.  
  5. import javax.swing.JPasswordField;
  6. import javax.swing.JTextField;
  7. import javax.swing.JButton;
  8. import javax.swing.JLabel;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.SwingConstants;
  11. import java.awt.Font;
  12. import java.awt.event.*;
  13.  
  14. public class Login extends JFrame {
  15.  
  16. /**
  17. * @author Wanghley
  18. */
  19. private static final long serialVersionUID = 1L;
  20. private JPasswordField passwordField;
  21. private JTextField txtUser;
  22.  
  23. /**
  24. * Launch the application.
  25. */
  26. public static void main(String[] args) {
  27. EventQueue.invokeLater(new Runnable() {
  28. public void run() {
  29. try {
  30. Login frame = new Login();
  31. frame.setVisible(true);
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. });
  37. }
  38.  
  39. /**
  40. * Create the frame.
  41. */
  42. public static String user, password;
  43. public Login() {
  44.  
  45. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46. setBounds(100, 100, 345, 207);
  47. getContentPane().setLayout(null);
  48.  
  49. passwordField = new JPasswordField();
  50. passwordField.setBounds(78, 80, 230, 20);
  51. getContentPane().add(passwordField);
  52.  
  53. txtUser = new JTextField();
  54. txtUser.setBounds(78, 36, 230, 20);
  55. getContentPane().add(txtUser);
  56. txtUser.setColumns(10);
  57.  
  58. JButton btnLogin = new JButton("Login");
  59. btnLogin.addActionListener(new ActionListener(){
  60. public void actionPerformed(ActionEvent evt) {
  61. String users = txtUser.getText();
  62. char[] pass = passwordField.getPassword();
  63. String passw = null;
  64. for (int i = 0; i < pass.length; i++) {
  65. passw = pass[i]+"";
  66. }
  67. Login(evt);
  68. }
  69. });
  70. btnLogin.setBounds(123, 121, 106, 37);
  71. getContentPane().add(btnLogin);
  72.  
  73. JLabel lblPassword = new JLabel("Password:");
  74. lblPassword.setHorizontalAlignment(SwingConstants.RIGHT);
  75. lblPassword.setBounds(10, 83, 58, 14);
  76. getContentPane().add(lblPassword);
  77.  
  78. JLabel lblUser = new JLabel("User:");
  79. lblUser.setHorizontalAlignment(SwingConstants.RIGHT);
  80. lblUser.setBounds(10, 39, 58, 14);
  81. getContentPane().add(lblUser);
  82.  
  83. JLabel lblLoginAdmin = new JLabel("Login Admin");
  84. lblLoginAdmin.setHorizontalAlignment(SwingConstants.CENTER);
  85. lblLoginAdmin.setFont(new Font("Liberation Sans", Font.BOLD, 14));
  86. lblLoginAdmin.setBounds(10, 0, 319, 25);
  87. getContentPane().add(lblLoginAdmin);
  88. }
  89. private static void Login(ActionEvent evt){
  90. //não consigo fechar a tela com o this.dispose();
  91. this.dispose();
  92. }
  93. }
Add Comment
Please, Sign In to add comment