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
    }

Do you mean the file is empty, or is there no file at all?
After line 9 try
System.out.println(Arrays.toString(Reg));
to help locate the problem.

hi
it does not change anyting :(
i put this line System.out.println(Arrays.toString(Reg));
on the line you specified.
Something is definetely missing but no idea...

If that didn't output anything then it suggests that your actionPerformed method isn't being called OR the if test on line 4 is failing...
NB You shouldn't compare Strings with ==
You must use the equals(...) method of the String class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.