fork download
  1. import java.awt.BorderLayout;
  2. import java.awt.FlowLayout;
  3. import java.awt.GridLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.BufferedReader;
  7. import java.io.BufferedWriter;
  8. import java.io.File;
  9. import java.io.FileReader;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import javax.swing.BorderFactory;
  13. import javax.swing.JButton;
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JPanel;
  17. import javax.swing.JPasswordField;
  18. import javax.swing.JTextField;
  19. import javax.swing.SwingConstants;
  20.  
  21. /**
  22.  * @author Kai Yuen Leong
  23.  */
  24.  
  25. @SuppressWarnings("serial")
  26. public class EquipmentLoanSystem extends JFrame {
  27.  
  28. private JButton button;
  29. private JLabel label;
  30. private JTextField usernameField;
  31. private JPasswordField passwordField;
  32. private static BufferedReader br;
  33. private static BufferedWriter bw;
  34. private boolean user;
  35. private boolean access;
  36.  
  37. public EquipmentLoanSystem() {
  38.  
  39. super("Equipment Loan System");
  40. setDefaultCloseOperation(EXIT_ON_CLOSE);
  41. add(makeMainPanel());
  42. pack();
  43. setVisible(true);
  44.  
  45. }
  46.  
  47. private JPanel makeMainPanel() {
  48.  
  49. Listener listener = new Listener();
  50.  
  51. JPanel textPanel = new JPanel(new GridLayout(2, 1));
  52. textPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
  53. label = new JLabel("Email", SwingConstants.CENTER);
  54. usernameField = new JTextField(10);
  55. textPanel.add(label);
  56. textPanel.add(usernameField);
  57.  
  58. label = new JLabel("Password", SwingConstants.CENTER);
  59. passwordField = new JPasswordField(10);
  60. textPanel.add(label);
  61. textPanel.add(passwordField);
  62.  
  63. JPanel buttonPanel = new JPanel(new FlowLayout());
  64. buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  65. button = new JButton("Sign In");
  66. button.addActionListener(listener);
  67. buttonPanel.add(button);
  68. button = new JButton("Register");
  69. button.addActionListener(listener);
  70. buttonPanel.add(button);
  71.  
  72. JPanel mainPanel = new JPanel(new BorderLayout());
  73. mainPanel.add(textPanel, BorderLayout.CENTER);
  74. mainPanel.add(buttonPanel, BorderLayout.SOUTH);
  75.  
  76. return mainPanel;
  77. }
  78.  
  79. private class Listener implements ActionListener {
  80.  
  81. @SuppressWarnings("deprecation")
  82. @Override
  83. public void actionPerformed(ActionEvent loginAccess) {
  84.  
  85. JButton button = (JButton) loginAccess.getSource();
  86.  
  87. if (!user) {
  88.  
  89. if (usernameField.getText().length() > 0) {
  90.  
  91. if (passwordField.getText().length() > 0) {
  92.  
  93. try {
  94. if (br.readLine() == null) {
  95.  
  96. bw.write(usernameField.getText());
  97. bw.write(" ");
  98. bw.write(passwordField.getText());
  99. bw.newLine();
  100. System.out.print("1");
  101. }
  102.  
  103. else if (br.readLine() != null) {
  104.  
  105. boolean read = true;
  106. String[] userAccess = new String[2];
  107.  
  108. while (read == true) {
  109.  
  110. String line = br.readLine();
  111. System.out.print(line);
  112. userAccess = line.split(" ", -1);
  113. if (userAccess[1] == usernameField.getText()
  114. && userAccess[2] == passwordField.getText()) {
  115.  
  116. access = true;
  117. read = false;
  118. System.out.print("2");
  119. }
  120.  
  121. else {read = true;}
  122.  
  123. }
  124. }
  125.  
  126. bw.close();
  127. br.close();
  128.  
  129. } catch (IOException e) {
  130. // TODO Auto-generated catch block
  131. e.printStackTrace();
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138.  
  139. public static void main(String[] args) throws IOException {
  140.  
  141. // Create new file
  142. String path = "C:\\Users\\kaiyu\\workspace\\Final Project - Equipment Loan System\\UserDatabase.txt";
  143. File file = new File(path);
  144.  
  145. if (!file.exists()) {
  146. file.createNewFile();
  147. }
  148.  
  149. FileWriter fw = new FileWriter(file.getAbsolutePath(), true);
  150. bw = new BufferedWriter(fw);
  151.  
  152. FileReader fr = new FileReader(file);
  153. br = new BufferedReader(fr);
  154.  
  155. new EquipmentLoanSystem();
  156. }
  157. }
  158.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:26: error: class EquipmentLoanSystem is public, should be declared in a file named EquipmentLoanSystem.java
public class EquipmentLoanSystem extends JFrame {
       ^
1 error
stdout
Standard output is empty