Calculator GUI using swing package
953811Aug 22 2012 — edited Aug 29 2012Hi everybody...
I'm writing the code for a calculator GUI using the swing package. I'm able to create all the components like the frame, text field and also the buttons. I learnt that I need to add ActionListeners to the components.
Like for example.. i did this in one of the classes...
{
JButton b1 = new JButton("1");
t1.addActionListener(new ButtonHandler());
}
and the other class..
import javax.swing.*;
import javax.xml.bind.DatatypeConverter;
import java.awt.BorderLayout;
import java.awt.event.*;
public class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
int x=0;
String s = " "+e.getActionCommand();
x= DatatypeConverter.parseInt(s);
}
}
Now my question is, How can i get the value of "x" out of the ButtonHandler class, and into the main method, so that i can operate on the value of it? or if you can suggest me any other better program, you may please...
Thanks in advance..