Commit 999f0792 authored by 9831111's avatar 9831111 🙂

Add initRemindMe method.

parent ae240047
...@@ -28,12 +28,13 @@ public class LoginFrame extends JFrame { ...@@ -28,12 +28,13 @@ public class LoginFrame extends JFrame {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBounds(700, 250, 320, 515); setBounds(700, 250, 320, 515);
initLoginFrame(); initLoginFrame();
// initRemindMe(); initRemindMe();
// initInformationPanel(); // initInformationPanel();
setVisible(true); setVisible(true);
} }
public void initLoginFrame() { public void initLoginFrame() {
tankPhoto = new ImageIcon("gifFiles/gif.gif"); tankPhoto = new ImageIcon("gifFiles/gif.gif");
...@@ -65,6 +66,24 @@ public class LoginFrame extends JFrame { ...@@ -65,6 +66,24 @@ public class LoginFrame extends JFrame {
} }
public void initRemindMe() {
File accounts = new File("Accounts.txt");
try (Scanner scanner = new Scanner(new FileReader(accounts))) {
String account;
while (scanner.hasNextLine()) {
account = scanner.nextLine() + "\n";
String[] strings = account.split(" ");
if (account.contains("true")) {
remindMe.setSelected(true);
userName.setText(strings[0]);
passwordField.setText(strings[1]);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void signUpUser(File accounts) { public void signUpUser(File accounts) {
try (FileWriter fileWriter = new FileWriter(accounts, true)) { try (FileWriter fileWriter = new FileWriter(accounts, true)) {
fileWriter.write(userName.getText() + " " + passwordField.getText() + " " + remindMe.isSelected() + " 0 0 0 0 0 " + "\n"); fileWriter.write(userName.getText() + " " + passwordField.getText() + " " + remindMe.isSelected() + " 0 0 0 0 0 " + "\n");
...@@ -77,6 +96,7 @@ public class LoginFrame extends JFrame { ...@@ -77,6 +96,7 @@ public class LoginFrame extends JFrame {
} }
} }
public void signInUser() { public void signInUser() {
File accounts = new File("Accounts.txt"); File accounts = new File("Accounts.txt");
try (Scanner scanner = new Scanner(new FileReader(accounts))) { try (Scanner scanner = new Scanner(new FileReader(accounts))) {
...@@ -103,12 +123,14 @@ public class LoginFrame extends JFrame { ...@@ -103,12 +123,14 @@ public class LoginFrame extends JFrame {
} }
} }
class SignInAction implements ActionListener { class SignInAction implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
signInUser(); signInUser();
} }
} }
class SignUpAction implements ActionListener { class SignUpAction implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
...@@ -132,5 +154,4 @@ public class LoginFrame extends JFrame { ...@@ -132,5 +154,4 @@ public class LoginFrame extends JFrame {
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment