Results 1 to 7 of 7
  1. #1
    deeadeed is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default how would i get this to work...?

    private void requestJButtonActionPerformed (ActionEvent event)
    {

    Writer fw = null;

    try
    {
    fw = new FileWriter( "customer.txt" );
    fw.write( phoneJTextField + "," + postcodeJTextField );
    }
    catch ( IOException e ) {
    System.err.println( "Cannot write to file" );
    }
    finally {
    if ( fw != null )
    try { fw.close(); } catch ( IOException e ) { }
    }


    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    JTextField phoneJTextField    = new JTextField("Beachwood 45789");
    JTextField postcodeJTextField = new JTextField("99231");
    Writer fw = null; 
    
    try 
    { 
        fw = new FileWriter( "customer.txt" ); 
        String phoneNumber = phoneJTextField.getText();
        String postalCode = postcodeJTextField.getText();
        fw.write( phoneNumber + "," + postalCode ); 
    }
    catch ( IOException e ) { 
        System.err.println( "Cannot write to file" ); 
    } 
    finally { 
        if ( fw != null ) 
        try {
            fw.close();
        } catch ( IOException e ) {
            System.out.println("Close error: " + e.getMessage());
        } 
    }

  3. #3
    deeadeed is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default

    sorry i should have explained the programme i guess.
    phoneJTextField etc will have user input on a form.

    when a button is pressed i would like the programme to write what is in the fields to file...having trouble getting this working :(

  4. #4
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Java Code:
    BufferedWriter wrt = new BufferedWriter(new FileWriter(
    					"test/test2.txt"));
    wrt.append(phoneJTextField.getText());
    wrt.close();
    That should be in your ActionListener for the button you press.

  5. #5
    deeadeed is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default

    im still stuck with htis :( can i email the code to someone to take a look at and sort out?

    thanks

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    You can post it here or send it in a PM.

  7. #7
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    For those who read PMs. Although generally it is frowned upon by people like me, therefore i dont answer them, and there is no way in hell i am giving you my email. The forum is here for a reason.

Similar Threads

  1. Synchronization Doesn't seem to work
    By sherinpearl in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2008, 06:30 PM
  2. Will this applet ever work?
    By willemjav in forum Java Applets
    Replies: 4
    Last Post: 04-20-2008, 05:40 PM
  3. Work On Lucene
    By peiceonly in forum Lucene
    Replies: 1
    Last Post: 08-07-2007, 05:47 PM
  4. what do I have to install to work with JSP
    By boy22 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-05-2007, 04:08 AM
  5. Program don't work
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-04-2007, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •