Advertisement
Guest User

Untitled

a guest
Apr 5th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. package LoginMarvin;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class MarvinEins extends JFrame implements ActionListener {
  9.  
  10. Icon x = new ImageIcon(getClass().getResource("HalloHallo.png"));
  11.  
  12. Container container = getContentPane();
  13. JLabel alter = new JLabel("Thank you for using my Software.");
  14. JLabel luser = new JLabel("made by Marvin");
  15. JLabel userLabel = new JLabel("USERNAME");
  16. JLabel passwordLabel = new JLabel("PASSWORD");
  17. JTextField userTextField = new JTextField();
  18. JPasswordField passwordField = new JPasswordField();
  19. JButton loginButton = new JButton("LOGIN");
  20. JButton resetButton = new JButton("RESET");
  21. JButton hallo = new JButton("", x);
  22. JCheckBox showPassword = new JCheckBox("Show Password");
  23.  
  24.  
  25. MarvinEins() {
  26. setLayoutManager();
  27. setLocationAndSize();
  28. addComponentsToContainer();
  29. addActionEvent();
  30.  
  31. }
  32.  
  33. public void setLayoutManager() {
  34. container.setLayout(null);
  35. }
  36.  
  37. public void setLocationAndSize() {
  38. alter.setBounds(1, 1, 500, 100);
  39. luser.setBounds(1, 30, 500, 100);
  40. userLabel.setBounds(50, 150, 100, 30);
  41. passwordLabel.setBounds(50, 220, 100, 30);
  42. userTextField.setBounds(150, 150, 150, 30);
  43. passwordField.setBounds(150, 220, 150, 30);
  44. showPassword.setBounds(150, 250, 150, 30);
  45. loginButton.setBounds(50, 300, 100, 30);
  46. resetButton.setBounds(200, 300, 100, 30);
  47. hallo.setBounds(20, 350, 300, 200);
  48.  
  49.  
  50. }
  51.  
  52. public void addComponentsToContainer() {
  53. container.add(luser);
  54. container.add(alter);
  55. container.add(userLabel);
  56. container.add(passwordLabel);
  57. container.add(userTextField);
  58. container.add(passwordField);
  59. container.add(showPassword);
  60. container.add(loginButton);
  61. container.add(resetButton);
  62. container.add(hallo);
  63. }
  64.  
  65. public void addActionEvent() {
  66. loginButton.addActionListener(this);
  67. resetButton.addActionListener(this);
  68. showPassword.addActionListener(this);
  69. }
  70.  
  71.  
  72. @Override
  73. public void actionPerformed(ActionEvent e) {
  74. //Coding Part of LOGIN button
  75.  
  76.  
  77. if (e.getSource() == loginButton) {
  78. String userText;
  79. String pwdText;
  80. userText = userTextField.getText();
  81. pwdText = passwordField.getText();
  82. if (userText.equalsIgnoreCase("Super") && pwdText.equalsIgnoreCase("Hallo")) {
  83. JOptionPane.showMessageDialog(this, "Login Successful");
  84. JFrame meinJFrame = new JFrame();
  85. meinJFrame.setTitle("Eingabe");
  86. meinJFrame.setSize(300, 150);
  87. JPanel panel = new JPanel();
  88.  
  89. JLabel label = new JLabel("Eingabe");
  90. panel.add(label);
  91.  
  92. // Textfeld wird erstellt
  93. // Text und Spaltenanzahl werden dabei direkt gesetzt
  94. JTextField tfName = new JTextField("", 15);
  95. // Schriftfarbe wird gesetzt
  96. tfName.setForeground(Color.black);
  97. // Hintergrundfarbe wird gesetzt
  98. tfName.setBackground(Color.white);
  99. // Textfeld wird unserem Panel hinzugefügt
  100. panel.add(tfName);
  101.  
  102. JButton buttonOK = new JButton("OK");
  103. panel.add(buttonOK);
  104.  
  105. meinJFrame.add(panel);
  106. meinJFrame.setVisible(true);
  107.  
  108.  
  109.  
  110. } else {
  111. JOptionPane.showMessageDialog(this, "Invalid Username or Password");
  112. }
  113.  
  114. }
  115. //Coding Part of RESET button
  116. if (e.getSource() == resetButton) {
  117. userTextField.setText("");
  118. passwordField.setText("");
  119. }
  120. //Coding Part of showPassword JCheckBox
  121. if (e.getSource() == showPassword) {
  122. if (showPassword.isSelected()) {
  123. passwordField.setEchoChar((char) 0);
  124. } else {
  125. passwordField.setEchoChar('*');
  126. }
  127.  
  128.  
  129. }
  130. }
  131.  
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. package LoginMarvin;
  155.  
  156. import java.awt.Color;
  157.  
  158. import javax.swing.JFrame;
  159.  
  160. public class MarvinZwei {
  161. public static void main(String[] a) {
  162. MarvinEins frame = new MarvinEins();
  163. frame.setTitle("Login");
  164. frame.setVisible(true);
  165. frame.setBounds(10, 10, 370, 600);
  166. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  167. frame.setResizable(false);
  168. frame.getContentPane().setBackground(Color.green);
  169. }
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement