Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. package flippjar;
  2.  
  3. import java.util.*;
  4. import java.awt.*;
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7. import java.util.concurrent.TimeUnit;
  8. import java.io.*;
  9.  
  10. class FlippGUI extends JFrame implements ActionListener {
  11.  
  12. private JButton button, button2;
  13. private JLabel label, label2;
  14. private JTextField text, text2;
  15. private String username = "";
  16. private String password = "";
  17. private String[] line, line2 = new String[6];
  18. private String[] name = new String[6];
  19. private String[] pswd = new String[6];
  20.  
  21. public FlippGUI() throws IOException {
  22. Scanner key = new Scanner(System.in);
  23.  
  24. setTitle("Flipp Systems Login");
  25. setLayout(null);
  26. setSize(500, 250);
  27. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. getContentPane().setBackground(null);
  29. setVisible(true);
  30.  
  31. text = new JTextField(20);
  32. text.setLocation(195, 73);
  33. text.setText("Username");
  34. text.setSize(120, 17);
  35.  
  36. text2 = new JTextField(20);
  37. text2.setLocation(195, 102);
  38. text2.setText("Password");
  39. text2.setSize(120, 17);
  40.  
  41. label = new JLabel("Please enter a password: ");
  42. label.setLocation(30, 60);
  43. label.setSize(300, 100);
  44. label.setForeground(Color.black);
  45. label.setFont(new Font("Arial", Font.PLAIN, 14));
  46.  
  47. label2 = new JLabel("Please enter a username: ");
  48. label2.setLocation(30, 30);
  49. label2.setSize(300, 100);
  50. label2.setForeground(Color.black);
  51. label2.setFont(new Font("Arial", Font.PLAIN, 14));
  52.  
  53. button = new JButton("Enter");
  54. button.setLocation(375, 200);
  55. button.setSize(100, 15);
  56. button.addActionListener(this);
  57.  
  58. button2 = new JButton("Exit");
  59. button2.setLocation(25, 200);
  60. button2.setSize(100, 15);
  61. button2.addActionListener(this);
  62.  
  63. getContentPane().add(button);
  64. getContentPane().add(button2);
  65. getContentPane().add(label);
  66. getContentPane().add(text);
  67. getContentPane().add(label2);
  68. getContentPane().add(text2);
  69.  
  70. File u = new File("usernames.txt");
  71. Scanner numScan = new Scanner(u);
  72. File p = new File("passwords.txt");
  73. Scanner numScan2 = new Scanner(p);
  74. do {
  75. for(int j = 0;j < 6;j++) {
  76. line[j] = numScan.nextLine();
  77. line2[j] = numScan2.nextLine();
  78. }
  79. }while(numScan.hasNextLine() && numScan2.hasNextLine());
  80.  
  81. }
  82.  
  83. public void actionPerformed(ActionEvent e) {
  84. if(e.getSource() == button) {
  85. username = text.getText();
  86. password = text2.getText();
  87. if(username.equals(line)) {
  88. if(password.equals(line2)) {
  89. JOptionPane.showMessageDialog(null, "Welcome!");
  90. return;
  91. }
  92. }
  93. }
  94. if(e.getSource() == button) {
  95. username = text.getText();
  96. password = text2.getText();
  97. if(username.equals(line)) {
  98. if(!password.equals(line2)) {
  99. JOptionPane.showMessageDialog(null, "Incorrect password!");
  100. return;
  101. }
  102. }
  103. }
  104. if(e.getSource() == button) {
  105. username = text.getText();
  106. password = text2.getText();
  107. if(!username.equals(line)) {
  108. JOptionPane.showMessageDialog(null, "Incorrect username!");
  109. }
  110. }
  111. }
  112.  
  113. }
  114.  
  115. public class FlippJar {
  116. public static void main(String args[]) throws IOException {
  117. FlippGUI applet = new FlippGUI();
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement