Java: How to immediately send changes in a text field to a file?
-
24-09-2019 - |
Question
Is it hard to do the following with the Java? First I need to generate a window with a text field (no buttons, nothing, just a text field). Than, when a user types a symbol in the text filed, program immediately stores information about this in a file (which symbol was typed and when). That's it.
Solution
No, it's not hard. The following code snippet may get you running with the JTextField:
http://www.java2s.com/Code/Java/Swing-JFC/TextfieldsandJavaevents.htm
and this can help with writing to a file:
http://www.java2s.com/Code/Java/File-Input-Output/WritelinesoftexttofileusingaPrintWriter.htm
OTHER TIPS
So you should read something about JFrame and JTextField and after (Add)ActionListeners (function in JTextField) in java and File Streams like FileInputStream and FileOutputStream. It's very easy !