You could attempt to do this by trying to make the variables accessible to the entire class.
To implement this, you can add the variable declaration where you have declared your User Interface items, after the class declaration.
You could then access this variable in another class.
Example Code:
public class TextArea1{
JTextArea text;
JFrame frame;
JTextField textField;
public int sampleIntToBeUsed;
You could also implement this with various get/set methods.
How to Make a Constructor: (Put the name of the class with no return type)
class startButtonListener implements ActionListener {
ArrayList aList;
startButtonListener(ArrayList passedInList)
{
aList = passedInList;
}
New Second ActionListener
class startTextFieldListener implements ActionListener {
String correctAnswer;
startTextFieldListener(String answer)
{
correctAnswer = answer;
}
@Override
public void actionPerformed(ActionEvent event) {
if (text.getText().equals(correctAnswer)) {
JOptionPane.showMessageDialog(null, "Hooray!");
}
else {
JOptionPane.showMessageDialog(null, "Wrong!");
}
}
}
}