I am trying to retrieve the information from a TextArea which has been defined as follows
JTextArea a1 = new JTextArea(15, 50);
a1.setEditable(true);
centerPanel.add(a1);
a1.setVisible(true);
and in my listener class
private class JobHandler implements ActionListener {
boolean c2shortHand = false;
boolean c1translation = false;
boolean c3onsite = false;
String custName = "";
String jobInfo ="";
String line = "";
public void actionPerformed(ActionEvent e) {
jobInfo=a1.getText();
if (c1.isSelected()) {
c1translation = true;
}
if (c2.isSelected()) {
c2shortHand = true;
}
if (c3.isSelected()) {
c3onsite = true;
}jobInfo=a1.getText();
}
}
When i run the GUI it is fine until i added the last part, where i am trying to assign the TextArea information to a String variable called jobInfo
The Error i get is, which seems to be complaining about threading. Is the problem the fact that i am trying to retrieve the information without doing something else first?
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at JobsGUI$JobHandler.actionPerformed(JobsGUI.java:202)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
The declaration of a1
public class JobsGUI {
private Manager mmm = new Branch("Watford");
private JFrame myFrame = new JFrame("Jobs GUI");
private Container contentPane = myFrame.getContentPane();
private JButton quitButton = new JButton("Quit");
private JButton addJobButton = new JButton("Add Job");
private JButton clearListButton = new JButton("Clear List");
private JPanel eastPanel = new JPanel();
private JPanel westPanel = new JPanel();
private JPanel centerPanel = new JPanel();
private JPanel northPanel = new JPanel();
private JPanel southPanel = new JPanel();
JCheckBox c1, c2, c3;
JTextField t1, t2, t3;
JLabel l1, l2;
JTextArea a1;
JScrollPane s1;
public JobsGUI() {
addAllStaff();
makeFrame();
makeMenus(myFrame);
makeTypes();
addJobs();
}
private void addJobs() {
t1 = new JTextField(10); //Customer name
northPanel.add(t1);
l1 = new JLabel("Enter Customer name here");
northPanel.add(l1);
c1 = new JCheckBox("Translation");
westPanel.add(c1);
c2 = new JCheckBox("ShortHand?");
westPanel.add(c2);
c3 = new JCheckBox("OnSite");
westPanel.add(c3);
JLabel l2 = new JLabel("Job Information");
centerPanel.add(l2);
l2.setVisible(true);
JTextArea a1 = new JTextArea(15, 50);
a1.setEditable(true);
centerPanel.add(a1);
a1.setVisible(true);
addJobButton.addActionListener(new JobHandler());