Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Applet that writes some data to txt file

Fredric Christian
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9362
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Run away! Run away! Here, take this tiny ad with you:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!