Dear All
I am trying to learn JAVA with Eclipse.I have a class like Form.java and it has a form which contains 4 text fields.When I press the submit button(Register) I want my program to put every thing into a file(test.txt) line by line.
I tried to do something from my study book but it does not work.I can not see any input in the external file.
I would be very happy if anyone can help me to learn further
Thanks in advance
Here is the codes
public class Form extends JFrame implements ActionListener
{
String[] Reg = {"","","",""};
JButton b1;
JTextField tf1;
JTextField tf2;
JTextField tf3;
JTextField tf4;
please assume the rest of codes are working well!
public void actionPerformed(ActionEvent ae)
{
String strSource = ae .getActionCommand( );
if(strSource=="Register")
{
Reg[0]=tf1.getText();
Reg[1]=tf2.getText();
Reg[2]=tf3.getText();
Reg[3]=tf4.getText();
PrintWriter print;
try
{
print=new PrintWriter(new BufferedWriter(new FileWriter("test.txt")));
for(int x=0; x<4; x++)
{
print.print(Reg[x] + " ");
}
print.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}//end if
}