Fairly new to Java: JTextFields help!!!

From: DJM (DJM_666_at_msn.com)
Date: 03/28/04


Date: 28 Mar 2004 03:27:19 -0800

I have a program with a few JTextFields. How do I store what is input
into these fields in a text file?

Below is some sample code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GUI extends JFrame implements ActionListener
{

private JTextField jtfCustID, jtfTransType, jtfDiff, jtfOpeningBal,
jtfClosingBal, jtfTransDate;
private JButton jbConfirm;
    
public GUI()
{
this.setTitle("GUI");
this.setSize(400,300);

jtfCustID = new JTextField();
jtfTransType = new JTextField();
jtfDiff = new JTextField();
jtfOpeningBal = new JTextField();
jtfClosingBal = new JTextField();
jtfTransDate = new JTextField();

jbConfirm = new JButton("Confirmation");

Container cp = this.getContentPane();
cp.setLayout(new GridLayout(8,2));

cp.add(new JLabel("Customer ID"));
cp.add(jtfCustID);

cp.add(new JLabel("Transaction Type"));
cp.add(jtfTransType);

cp.add(new JLabel("Opening/Closing Difference"));
cp.add(jtfDiff);

cp.add(new JLabel("Opening Balance"));
cp.add(jtfOpeningBal);

cp.add(new JLabel("Closing Balance"));
cp.add(jtfClosingBal);

cp.add(new JLabel("Date of Transaction"));
cp.add(jtfTransDate);

cp.add(jbConfirm);

jtfCustID.addActionListener(this);
jtfTransType.addActionListener(this);
jtfDiff.addActionListener(this);
jtfOpeningBal.addActionListener(this);
jtfClosingBal.addActionListener(this);
jtfTransDate.addActionListener(this);

jbConfirm.addActionListener(this);

}// end constructor GUI()

public void actionPerformed(ActionEvent event){

if (event.getSource() == jbConfirm) ;

}// end method actionPerformed()

public static void main(String [] arg){
GUI frame = new GUI();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}//end method main()
}// end class GUI

What code would I have to use, to save (into a text file) what is
input into the: jtfCustID, jtfTransType, jtfDiff, jtfOpeningBal,
jtfClosingBal, and jtfTransDate fields?????



Relevant Pages

  • Re: GUI =?ISO-8859-1?Q?Anf=E4nger_?=
    ... ich muss eine bestehende Klasse Swaper an ein GUI Anbinden: ... IMHO sollte das Ding Swapper und nicht Swaper heissen... ... private JTextField jTextFieldRechts; ...
    (de.comp.lang.java)
  • MVC and java design
    ... Take the GUI as reference, and make calls to the getTextof the ... JTextField to get the filename. ... Use a central Settings class with all User settings recorded ...
    (comp.lang.java.gui)
  • Re: help
    ... console but i want to convert to a GUI. ... It would compile and the GUI itself could show, if it weren't for the method ... JTextField doesn't have any method "exists" ... File infile = new File; ...
    (comp.lang.java.programmer)
  • Fairly new to Java: JTextFields help!!!
    ... public class GUI extends JFrame implements ActionListener ... private JTextField jtfCustID, jtfTransType, jtfDiff, jtfOpeningBal, ...
    (comp.lang.java.programmer)