GUI supports the FileWriting

View: New views
3 Messages — Rating Filter:   Alert me  

GUI supports the FileWriting

by yamada :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can I have any example source programs that enable me to store in a file
opened  the  data which are input in GUI TextField(s),
 for example.?

yoshiaki yamada (NAPRA)
y-yamada@...


Re: GUI supports the FileWriting

by Jana Maleckova :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi yamada,
just create e.g. new JFrame in GUI Builder.
1. Place there jTextField with jButton.
2. Invoke context menu on jButton and choose Events -> Action
->actionPerformed (you will be automatically switched into source code)
3. write e.g. this code in handler

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String filename = "c:/test.txt";
FileWriter writer = null;
try {
try {
writer = new FileWriter(filename);
} catch (IOException ex) {
Logger.getLogger(NewJFrame4.class.getName()).log(Level.SEVERE, null, ex);
}
jTextField1.write(writer);
} catch (IOException exception) {
System.err.println("Save oops");
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException exception) {
System.err.println("Error closing writer");
exception.printStackTrace();
}
}
}
}

This should work.
Regards
Janie

yamada napsal(a):
> Can I have any example source programs that enable me to store in a file
> opened  the  data which are input in GUI TextField(s),
>  for example.?
>
> yoshiaki yamada (NAPRA)
> y-yamada@...
>
>  

Re: GUI supports the FileWriting

by PerfectReign :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 21 July 2008 09:30:52 pm yamada wrote:
> Can I have any example source programs that enable me to store in a file
> opened  the  data which are input in GUI TextField(s),
>  for example.?

Start here...

http://java.sun.com/developer/onlineTraining/tools/netbeans_part1/

...then go to a java tutorial on writing to files. You want to look for
FileWriter (http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html)
and find some examples as to how to go about this process.

Basically you get the value of the text field -

aString = textFieldName.getText()

- and then write it to a file...

    try {
        BufferedWriter out = new BufferedWriter(new
FileWriter("outfilename"));
        out.write("aString");
        out.close();
    } catch (IOException e) {
    }



http://exampledepot.com/egs/java.io/WriteToFile.html

--
kai
www.filesite.org || www.4thedadz.com || www.perfectreign.com
remember - a turn signal is a statement, not a request