i'm sorry if this question is already asked before, but i have tried to find this and i got nothing which match with my problem. my problem is how to validating login data based on .txt file in java gui (i use netbeans). i have 2 jFrame, first is MainMenu frame and Registration frame and i stuck in MainMenu. In registration class is no problem with saving data into .txt file. sample of .txt file here :
Name: Gifhary Age: 20 Amount: 2000 Account No: 1234 Password: blabla
file name is based on account no.
this is my Registration code
package banksimulator;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Registration extends javax.swing.JFrame {
static ArrayList name = new ArrayList();
static ArrayList age = new ArrayList();
static ArrayList amount = new ArrayList();
static ArrayList accountNo = new ArrayList();
static ArrayList password = new ArrayList();
/**
* Creates new form Registration
*/
public Registration() {
initComponents();
this.setLocationRelativeTo(null);
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {
String content = "Name: "+txtName.getText()+" Age: "+txtAge.getText()+" Amount: "+txtAmount.getText()+" Account No: "+txtAccountNo.getText()+" Password: "+txtPassword.getText();
try {
File file = new File("src/banksimulator/Registration/"+txtAccountNo.getText()+".txt");
if (!file.exists()) {
file.createNewFile();
FileWriter data = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(data);
bw.write(content);
bw.close();
JOptionPane.showMessageDialog(this, "Data Is Saved");
txtName.setText("");
txtAge.setText("");
txtAmount.setText("");
txtAccountNo.setText("");
txtPassword.setText("");
}
else {
JOptionPane.showMessageDialog(this, "Account Number Is Already Used");
txtAccountNo.setText("");
}
} catch (IOException e) {
}
// TODO add your handling code here:
}
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
MainMenu m = new MainMenu();
m.setVisible(true);
// TODO add your handling code here:
}
i skip some default code in "Generate Code"
and this is for MainMenu
package banksimulator;
import java.io.*;
import javax.swing.*;
/**
*
* @author Qodri
*/
public class MainMenu extends javax.swing.JFrame {
/**
* Creates new form MainMenu
*/
public MainMenu() {
initComponents();
this.setLocationRelativeTo(null);
}
private void registrationBtnActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
Registration r = new Registration();
r.setVisible(true);
// TODO add your handling code here:
}
private void logInBtnActionPerformed(java.awt.event.ActionEvent evt) {
String account = txtAccountNo.getText();
String password = txtPassword.getText();
//My problem is here
// TODO add your handling code here:
}
data required for MainMenu is Account No and Password if anyone can help me, please. and very thanks to you