a simple JButton and some output text on file. Doesn't work...

Discussion in 'Java' started by Bici, Jul 30, 2007.

  1. Bici

    Bici Guest

    Here's the code for a little program (APPLET). I tried to run it but
    when i click on the button to print my thing... well, nothing happens
    and then when i check the file there is nothing on it. What to do?

    Here's the function:

    public void ScrivisuFile(String percorsouno) {


    try {
    FileOutputStream file = new FileOutputStream(percorsouno);
    PrintStream Output = new PrintStream(file);

    Output.println("ma tu scrivi?");

    }

    catch (IOException e) {
    System.out.println("Errore: " + e);
    System.exit(1);
    }
    }

    **************************************************
    and here is when i actually call the function
    ****************************************************

    btBut1 = new JButton( "save" );
    gbcPanel0.gridx = 0;
    gbcPanel0.gridy = 3;
    gbcPanel0.gridwidth = 1;
    gbcPanel0.gridheight = 1;
    gbcPanel0.fill = GridBagConstraints.NONE;
    gbcPanel0.weightx = 0;
    gbcPanel0.weighty = 0;
    gbcPanel0.anchor = GridBagConstraints.EAST;
    gbcPanel0.insets = new Insets( 0,2,5,5 );
    gbPanel0.setConstraints( btBut1, gbcPanel0 );
    //AZIONE?
    btBut1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    ScrivisuFile("./bandiere/testouno.txt");
    }
    });
    pnPanel0.add( btBut1 );


    ********************************************

    And the strange thing is that when i click on the "save" button the
    button itself "freezes" (the background colour changes without getting
    back to normal until the curson is set away from the button itself...
    Any idea?
     
    Bici, Jul 30, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Owen
    Replies:
    1
    Views:
    456
    Natty Gur
    Jul 24, 2003
  2. Brian J. Sayatovic
    Replies:
    1
    Views:
    634
    Karsten Lentzsch
    Aug 13, 2003
  3. kevinc

    Jbutton and text

    kevinc, Nov 24, 2003, in forum: Java
    Replies:
    5
    Views:
    891
    Nosnos
    Nov 26, 2003
  4. Cloud Burst

    can JButton text span a line?

    Cloud Burst, Dec 15, 2003, in forum: Java
    Replies:
    3
    Views:
    3,030
    Alex Hunsley
    Dec 15, 2003
  5. Duane Evenson
    Replies:
    5
    Views:
    1,457
    RedGrittyBrick
    Sep 27, 2007
Loading...

Share This Page