Guest User

Untitled

a guest
May 30th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. package Login_Sys;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JOptionPane;
  8. import javax.swing.JPasswordField;
  9. import javax.swing.JTextField;
  10.  
  11. //Change to package you want after login Success//
  12. import test.test;
  13.  
  14. import javax.swing.JButton;
  15. import javax.swing.JSeparator;
  16. import java.awt.Color;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.ActionEvent;
  19. import java.awt.Font;
  20.  
  21. public class Login_S {
  22.  
  23. private JFrame frame;
  24. private JPasswordField txtPassword;
  25. private JTextField txtUsername;
  26.  
  27. /**
  28. * Launch the application.
  29. */
  30. public static void main(String[] args) {
  31. EventQueue.invokeLater(new Runnable() {
  32. public void run() {
  33. try {
  34. Login_S window = new Login_S();
  35. window.frame.setVisible(true);
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. });
  41. }
  42.  
  43. /**
  44. * Create the application.
  45. */
  46. public Login_S() {
  47. initialize();
  48. }
  49.  
  50. /**
  51. * Initialize the contents of the frame.
  52. */
  53. private void initialize() {
  54. frame = new JFrame();
  55. frame.getContentPane().setBackground(Color.DARK_GRAY);
  56. frame.setBounds(200, 200, 500, 300);
  57. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58. frame.getContentPane().setLayout(null);
  59.  
  60. JLabel lblNewLabel = new JLabel("Login");
  61. lblNewLabel.setForeground(Color.WHITE);
  62. lblNewLabel.setFont(new Font("Dialog", Font.BOLD, 25));
  63. lblNewLabel.setBounds(195, 12, 161, 32);
  64. frame.getContentPane().add(lblNewLabel);
  65.  
  66. JLabel lblNewLabel_1 = new JLabel("Username");
  67. lblNewLabel_1.setForeground(Color.WHITE);
  68. lblNewLabel_1.setFont(new Font("Dialog", Font.BOLD, 17));
  69. lblNewLabel_1.setBounds(58, 87, 109, 15);
  70. frame.getContentPane().add(lblNewLabel_1);
  71.  
  72. JLabel lblNewLabel_2 = new JLabel("Password");
  73. lblNewLabel_2.setForeground(Color.WHITE);
  74. lblNewLabel_2.setFont(new Font("Dialog", Font.BOLD, 17));
  75. lblNewLabel_2.setBounds(58, 156, 109, 15);
  76. frame.getContentPane().add(lblNewLabel_2);
  77.  
  78. txtPassword = new JPasswordField();
  79. txtPassword.setBounds(185, 154, 124, 19);
  80. frame.getContentPane().add(txtPassword);
  81.  
  82. txtUsername = new JTextField();
  83. txtUsername.setBounds(185, 85, 124, 19);
  84. frame.getContentPane().add(txtUsername);
  85. txtUsername.setColumns(10);
  86.  
  87.  
  88. JButton btnLogin = new JButton("Login");
  89. btnLogin.setForeground(Color.GREEN);
  90. btnLogin.addActionListener(new ActionListener() {
  91. public void actionPerformed(ActionEvent e)
  92. {
  93. String password = txtPassword.getText();
  94. String username = txtUsername.getText();
  95.  
  96. //Teste das pass //
  97. if (password.contains("test") && username.contains("test")) {
  98.  
  99. txtPassword.setText(null);
  100. txtUsername.setText(null);
  101.  
  102. test info = new test();
  103. test.main(null);
  104.  
  105.  
  106. }
  107. else
  108. {
  109.  
  110. JOptionPane.showMessageDialog(null, "Ah Ah Ah Du hast das Zauberwort nicht gesagt!!!","Zugriff Verweigert", 0);
  111. txtPassword.setText(null);
  112. txtUsername.setText(null);
  113. }
  114. }
  115. });
  116. btnLogin.setBounds(53, 218, 114, 25);
  117. frame.getContentPane().add(btnLogin);
  118.  
  119. JButton btnReset = new JButton("Reset");
  120. btnReset.setForeground(Color.ORANGE);
  121. btnReset.addActionListener(new ActionListener() {
  122. public void actionPerformed(ActionEvent arg0) {
  123. txtUsername.setText(null);
  124. txtPassword.setText(null);
  125. }
  126. });
  127. btnReset.setBounds(195, 218, 114, 25);
  128. frame.getContentPane().add(btnReset);
  129.  
  130. JButton btnExit = new JButton("Exit");
  131. btnExit.setForeground(Color.RED);
  132. btnExit.addActionListener(new ActionListener() {
  133. public void actionPerformed(ActionEvent arg0) {
  134.  
  135. JFrame frmLoginSystem = new JFrame("Exit");
  136. if (JOptionPane.showConfirmDialog(frmLoginSystem, "Confirm Exit", "Login System",
  137. JOptionPane.YES_NO_OPTION)== JOptionPane.YES_NO_OPTION) {
  138. System.exit(0);
  139. }
  140. }
  141. });
  142. btnExit.setBounds(336, 218, 114, 25);
  143. frame.getContentPane().add(btnExit);
  144.  
  145. JSeparator separator = new JSeparator();
  146. separator.setForeground(Color.BLACK);
  147. separator.setBackground(Color.BLACK);
  148. separator.setBounds(0, 202, 488, 2);
  149. frame.getContentPane().add(separator);
  150.  
  151. JSeparator separator_1 = new JSeparator();
  152. separator_1.setForeground(Color.BLACK);
  153. separator_1.setBackground(Color.BLACK);
  154. separator_1.setBounds(0, 51, 511, 2);
  155. frame.getContentPane().add(separator_1);
  156. }
  157. }
Add Comment
Please, Sign In to add comment