I have added set of integers to a JTextArea for each button click.
what exactly I want is that I want to add all the integers and display in a separate JTextArea
,Also I want to ask whether we can access the value of a variable within an action listener outside the action listener.
Here is the code:
private ActionListener listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if(evt.getActionCommand().equals(t.getText()))
{
onec=one.calone(n);
td.append(Double.toString(onec));
td.append("\n");
}
res=Integer.parseInt(td.getText());
}
};
When the user presses button 't' It will keep on adding the integer 'onec' to textarea 'td' using append method.And I have stored the result from the action listener into a variable 'res' of double datatype.
private ActionListener listener2 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(tot.getText()))
{
totd.setText(Double.toString(res));
}
}
};
When the user clicks the button 'tot',It should add all the integers in the textarea 'td' and display it in the textarea 'totd'. This code is not working. Please help me this is the last part of my project.