I recently make a class where it outputs to a .txt file. I want now on a "different class" to read the code (it's a sign up program/sign in) for example, a user registered, and then when he loses his info, he could get them back using a JButton and entering in an scode that he set up once he signed up.. but I know how to make the class read the files but I don't know how will I use them here is the code that outputs:
package malkawi.login;
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.*;
import javax.swing.*;
import malkawi.login.JTextFieldLimit;
/**
*
* @author Defiledx1
* sign up
*/
public class SignUp extends JFrame implements EventListener {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton complete = new JButton("Next");
JLabel fname = new JLabel("Name: ");
JLabel Mname = new JLabel("Middle Name: ");
JLabel Lname = new JLabel("Last Name: ");
JLabel user = new JLabel("Username: ");
JLabel pass = new JLabel("Password: ");
JLabel info = new JLabel("Click Next to Continue");
JLabel email = new JLabel("Email: ");
JLabel scode = new JLabel("Secret Code: ");
JTextField fname1 = new JTextField();
JTextField Mname1 = new JTextField();
JTextField Lname1 = new JTextField();
JTextField user1 = new JTextField();
JPasswordField pass1 = new JPasswordField();
JTextField email1 = new JTextField();
JTextField scode1 = new JTextField();
JRadioButton showPass = new JRadioButton("Show Pass");
boolean good;
public SignUp() {
super("Sign Up - Flare By Malkawi");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(600, 400);
setResizable(false);
setVisible(true);
JTextFieldFilter jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
jtff.setNegativeAccepted(true);
setVisible(true);
setLayout(new GridLayout(0, 2, 10, 10));
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
/*
* Limitations
*/
fname1.setDocument(new JTextFieldLimit(10));
Mname1.setDocument(new JTextFieldLimit(1));
Lname1.setDocument(new JTextFieldLimit(10));
user1.setDocument(new JTextFieldLimit(15));
email1.setDocument(new JTextFieldLimit(80));
//scode1.setDocument(new JTextFieldLimit(5));
scode1.setDocument(jtff);
/*
* End Of Limitations
*/
/*
* RadioButton Checked : Unchecked
*/
showPass.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
showPassword(e.getStateChange() == 1 ? true : false);
}
});
/*
* End of RadioButton Checked : UnChecked
*/
/*
* Action of registration
*/
complete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
abilities();
if(good == false) {
abilities();
} else {
try {
outPutInformation();
} catch (FileNotFoundException | UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println("Flare is unable at the moment!");
}
}
}
});
/*
* End of Action of registration
*/
// Dimension labelSize = info.getPreferredSize();
/*
* Start of placements
*/
//add(info);
add(fname);
add(fname1);
add(Mname);
add(Mname1);
add(Lname);
add(Lname1);
add(user);
add(user1);
add(pass);
add(pass1);
add(email);
add(email1);
add(scode);
add(scode1);
add(complete);
add(showPass);
add(info);
pack();
}
String filename1 = user1.getText();
String firstname1 = fname1.getText();
String middlename1 = Mname1.getText();
String lastname1 = Lname1.getText();
String username1 = user1.getText();
@SuppressWarnings("deprecation")
String password1 = pass1.getText();
String hotmail1 = email1.getText();
String secretcode1 = scode1.getText();
public void abilities() {
if (firstname1.contains(JTextFieldFilter.ALPHA_NUMERIC)) {//tommorow defiled add more!!
JFrame abort = new JFrame("Firstname needs to contain numbers and letters");
JLabel label = new JLabel("Firstname needs to contain numbers and letters");
abort.setLayout(new BorderLayout());
abort.setDefaultCloseOperation(EXIT_ON_CLOSE);
abort.setSize(400, 200);
abort.setResizable(false);
abort.add(label, BorderLayout.CENTER);
abort.pack();
abort.setVisible(true);
good = false;
} else {
good = true;
}
}
public void showPassword(boolean showP) {
if (showP == true) {
pass1.setEchoChar((char)0);
} else {
pass1.setEchoChar('*');
}
}
/*
* File Output Requirements
String filename = user1.getText();
String firstname = fname1.getText();
String middlename = Mname1.getText();
String lastname = Lname1.getText();
String username = user1.getText();
@SuppressWarnings("deprecation")
String password = pass1.getText();
String hotmail = email1.getText();
String secretcode = scode1.getText();
* File Output done
*/
public void outPutInformation() throws FileNotFoundException, UnsupportedEncodingException {
String filename = user1.getText();
String firstname = fname1.getText();
String middlename = Mname1.getText();
String lastname = Lname1.getText();
String username = user1.getText();
@SuppressWarnings("deprecation")
String password = pass1.getText();
String hotmail = email1.getText();
String secretcode = scode1.getText();
PrintWriter writer = new PrintWriter("data/usersaves/"+filename+".txt", "UTF-8");
writer.println("First Name: "+firstname);
writer.println("Middle Name: "+middlename);
writer.println("Last Name: "+lastname);
writer.println("Username: "+username);
writer.println("Password: "+password);
writer.println("Email: "+hotmail);
writer.println("Secret Code: "+secretcode);
writer.close();
}
}
Thank you!