This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

Applet that writes some data to txt file

Fredric Christian
Greenhorn

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.

[code]
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 {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}

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.setText("Questions");
lblQuestions.setBounds(new Rectangle(140, 20, 55, 20));
radioTrue.setText("True");
radioTrue.setBounds(new Rectangle(105, 155, 55, 20));
radioFalse.setText("False");
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);
}
}
[code]

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

Joined: Oct 29, 2001
Posts: 8839
    
    7

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]
 
jQuery in Action, 2nd edition
 
subject: Applet that writes some data to txt file
 
Similar Threads
JLabel1.setText error
Switching between the frames
Newbie question about transferring data between classes
JTextField with JOptionPane - showMessageDialog (please help)
JTextArea