varriable passing to action event listeners
Hello all I have the following code:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.*;
import java.awt.event.*;
import java.awt.ActiveEvent;
import java.io.*;
public class AddDriverForm extends JFrame
{
private JLabel dName;
private JTextField dNameTxt;
private JLabel empnoLabel;
private JButton submit;
private JButton clear;
private JTextField empnoText;
public static void main(String[] args)
{
AddDriverForm inst = new AddDriverForm();
inst.setVisible(true);
}
public AddDriverForm()
{
super();
initGUI();
}
private void initGUI()
{
try
{
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setFocusableWindowState(false);
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7, 7};
thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
thisLayout.columnWidths = new int[] {7, 7, 7, 7};
getContentPane().setLayout(thisLayout);
this.setTitle("Add Driver - CANIS");
dNameTxt = new JTextField();
getContentPane().add(dNameTxt, new GridBagConstraints(1, 1, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
dName = new JLabel();
getContentPane().add(dName,new GridBagConstraints(0,1,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0, 0, 0, 0),0,0));
dName.setText("Driver Name");
empnoLabel = new JLabel();
getContentPane().add(empnoLabel,new GridBagConstraints(0,2,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0, 0, 0, 0),0,0));
empnoLabel.setText("Employee Number");
empnoText = new JTextField();
getContentPane().add(empnoText, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
SubmitListener subLis = new SubmitListener();
submit = new JButton();
getContentPane().add(submit,new GridBagConstraints(1,3,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0, 0, 0, 0),0,0));
submit.setText("Submit");
submit.addActionListener(subLis);
clear = new JButton();
getContentPane().add(clear, new GridBagConstraints(2,3,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE, new Insets(0, 0, 0, 0),0,0));
clear.setText("Clear");
pack();
setSize(400, 300);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
class SubmitListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
File file = new File("sqlOutput.txt");
String name="aname";
String empno="aempno";
try
{
PrintStream output = new PrintStream(file);
output.println("INSERT INTO Driver");
output.println("VALUES("+"'"+name+"','"+empno+"');");
output.close();
}
catch(FileNotFoundException fnfe)
{
fnfe.printStackTrace();
}
}
}
when the button is clicked i need to get the values from the text field and pass them to the event listener. Could anyone point me in the right direction would be greatful.
NB the 2 string varriables in the actionPerformed method are there to test only unless ofcourse I need them in any possible answer.

