wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Applet that writes some data to txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Applet that writes some data to txt file " Watch "Applet that writes some data to txt file " New topic

Applet that writes some data to txt file

Fredric Christian

Joined: Apr 05, 2006
Posts: 1
Hi I am new to this so I am trying to brake it down into sections, I am learing java from a book right know and I have not programed much so I am having some issues with this.
In the code below I want to take the text the user types into the text box and write it to a txt file. With two buttons one that will clear the txt field and one that will write the text file.

I understand how to do consul programs but cant get the hole user interface coding down could someone help please.

package ltproject;

import java.awt.Dimension;

import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;

public class LTInterface extends JFrame {
private JTextArea jTextArea1 = new JTextArea();
private JLabel lblQuestions = new JLabel();
private JRadioButton radioTrue = new JRadioButton();
private JRadioButton radioFalse = new JRadioButton();
private JButton btnNext = new JButton();

public LTInterface() {
try {
} catch (Exception e) {

private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize(new Dimension(354, 313));
this.setTitle( "Driving Test" );
jTextArea1.setBounds(new Rectangle(90, 45, 165, 100));
lblQuestions.setBounds(new Rectangle(140, 20, 55, 20));
radioTrue.setBounds(new Rectangle(105, 155, 55, 20));
radioFalse.setBounds(new Rectangle(185, 155, 55, 20));
btnNext.setText("Next Question");
btnNext.setBounds(new Rectangle(115, 195, 115, 70));
this.getContentPane().add(btnNext, null);
this.getContentPane().add(radioFalse, null);
this.getContentPane().add(radioTrue, null);
this.getContentPane().add(lblQuestions, null);
this.getContentPane().add(jTextArea1, null);

I dont know were to put code to make this do what I am thinking. if it is posible.
Joe Ess

Joined: Oct 29, 2001
Posts: 8927

You've got three questions here:
How to listen for a button press. Have a look at the Java Tutorial on How to Use Buttons.
How to get text out of a text area. Just invoke the getText() method on it.
And finally, how to write text to a file. Again, the Java Tutorial has a chapter on Input and Output. It doesn't tell you specifically how to write text to a file, but it should give you enough information to figure it out. If not, feel free to ask for another hint!

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Don't get me started about those stupid light bulbs.
subject: Applet that writes some data to txt file