Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JPanel;
  8. import javax.swing.JPasswordField;
  9. import javax.swing.JTextField;
  10.  
  11.  
  12. public class LoginUI extends JFrame implements ActionListener
  13. {
  14.  
  15.  
  16. JTextField Tusername;
  17. JTextField Tpassword;
  18. JButton Login = new JButton("Login");
  19. JButton register = new JButton("Register");
  20. JLabel passwordLabel = new JLabel("Password");
  21. JLabel userLabel = new JLabel("User");
  22.  
  23. public String username;
  24. public String password;
  25.  
  26. public LoginUI()
  27. {
  28.  
  29. JFrame frame = new JFrame("Login or register");
  30. JPanel Panel = new JPanel();
  31. frame.add(Panel);
  32. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.  
  34. Login.setBounds(10, 80, 80, 25);
  35. Panel.add(Login);
  36. Login.addActionListener(this);
  37.  
  38. register.setBounds(180, 80, 80, 25);
  39. Panel.add(register);
  40. register.addActionListener(this);
  41.  
  42. Panel.setLayout(null);
  43.  
  44. JLabel userLabel = new JLabel("User");
  45. userLabel.setBounds(10, 10, 80, 25);
  46. Panel.add(userLabel);
  47.  
  48. Tusername = new JTextField(20);
  49. Tusername.setBounds(100, 10, 160, 25);
  50. Panel.add(Tusername);
  51.  
  52. JLabel passwordLabel = new JLabel("Password");
  53. passwordLabel.setBounds(10, 40, 80, 25);
  54. Panel.add(passwordLabel);
  55.  
  56. Tpassword = new JPasswordField(20);
  57. Tpassword.setBounds(100, 40, 160, 25);
  58. Panel.add(Tpassword);
  59.  
  60. }
  61.  
  62.  
  63. public void actionPerformed(ActionEvent e)
  64. {
  65. if (e.getSource() == Login)
  66. {
  67. String username = Tusername.getText();
  68. System.out.println(username);
  69. }
  70. else if (e.getSource() == register)
  71. {
  72. String password = Tpassword.getText();
  73. System.out.println(password);
  74. }
  75. }
  76.  
  77.  
  78. public static void main(String args[])
  79. {
  80.  
  81.  
  82.  
  83.  
  84. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement