Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calculator GUI using swing package

953811Aug 22 2012 — edited Aug 29 2012
Hi 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..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2012
Added on Aug 22 2012
2 comments
365 views