Hey guys can u help me on my problem. I'm making a Login Page in java .Where the user will input his/her Username and Email and save it in a text file.. But the problem is I can't save multiple Username and emails In the text file it only save the current username and email of the user.Thanks in advance
package java_log_in;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public final class JAVA_FRAME {
JFrame f=new JFrame("LOGIN PAGE");
JLabel label=new JLabel("Enter Username");
JTextField tf=new JTextField(20);
JLabel label_2=new JLabel("Enter Email");
JTextField tf_2=new JTextField(20);
JButton button=new JButton("LOG IN");
public JAVA_FRAME(){
frame();
}
public void frame(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(250,250);
f.setVisible(true);
f.setLocationRelativeTo(null);
JPanel panel=new JPanel();
panel.setBackground(Color.YELLOW);
panel.add(label);
panel.add(tf);
panel.add(label_2);
panel.add(tf_2);
panel.add(button);
f.add(panel);
event e=new event();
button.addActionListener(e);
}
public class event implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
try {
String word=tf.getText();
String words=tf_2.getText(); `
FileWriter stream= new
FileWriter("C://Users//Keyboard//Desktop//file.txt");
BufferedWriter out = new BufferedWriter(stream);
out.write(word);
out.write(words);
out.close();
} catch(Exception ex){}
}
}
}