0

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){}     
     }         
 }

}

4
  • Take a closer look at the JavaDocs Commented Oct 27, 2017 at 3:22
  • I'd also consider having a look at BufferedWriter#newLine, it'll come in handy Commented Oct 27, 2017 at 3:24
  • You might also find try-with-resources useful Commented Oct 27, 2017 at 3:25
  • @MadProgrammer..I'll try ur suggestions sir and thank u Commented Oct 27, 2017 at 3:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.