I just improved my code, new code posted below
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class BasicGUI extends JFrame implements ActionListener {
private JButton b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, plus, equal;
private JTextField tf;
private JPanel display, keypad;
private GridLayout bGrid;
String outputTf = "";
int output = 0;
String n = "";
String i = "";
int num = 0;
public void actionPerformed(ActionEvent e) { // event handler
JButton b = (JButton) e.getSource();
if (b == b0) {
i = Integer.toString(0);
n = n + Integer.toString(0);
} else if (b == b1) {
i = Integer.toString(1);
n = n + Integer.toString(1);
} else if (b == b2) {
i = Integer.toString(2);
n = n + Integer.toString(2);
} else if (b == b3) {
i = Integer.toString(3);
n = n + Integer.toString(3);
} else if (b == b4) {
i = Integer.toString(4);
n = n + Integer.toString(4);
} else if (b == b5) {
i = Integer.toString(5);
n = n + Integer.toString(5);
} else if (b == b6) {
i = Integer.toString(6);
n = n + Integer.toString(6);
} else if (b == b7) {
i = Integer.toString(7);
n = n + Integer.toString(7);
} else if (b == b8) {
i = Integer.toString(8);
n = n + Integer.toString(8);
} else if (b == b9) {
i = Integer.toString(9);
n = n + Integer.toString(9);
} else if (b == plus) {
num = num + Integer.parseInt(n);
n="";
i = "+";
} else if (b == equal) {
output = num + Integer.parseInt(n);
i = "="+ output;
}
outputTf = outputTf + i;
tf.setText(outputTf);
}
public BasicGUI() {
super("My First GUI Application");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bGrid = new GridLayout(4, 3, 2, 2);
keypad = new JPanel(bGrid);
display = new JPanel();
b0 = new JButton("0");
b1 = new JButton("1");
b2 = new JButton("2");
b3 = new JButton("3");
b4 = new JButton("4");
b5 = new JButton("5");
b6 = new JButton("6");
b7 = new JButton("7");
b8 = new JButton("8");
b9 = new JButton("9");
plus = new JButton("+");
equal = new JButton("=");
keypad.add(b0);
keypad.add(b1);
keypad.add(b2);
keypad.add(b3);
keypad.add(b4);
keypad.add(b5);
keypad.add(b6);
keypad.add(b7);
keypad.add(b8);
keypad.add(b9);
keypad.add(plus);
keypad.add(equal);
tf = new JTextField(20);
display.add(tf);
this.add(display, BorderLayout.NORTH);
this.add(keypad, BorderLayout.SOUTH);
this.pack();
// register the event listener with the buttons
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
plus.addActionListener(this);
equal.addActionListener(this);
}
/**
* @param args
*/
public static void main(String[] args) {
new BasicGUI().setVisible(true);
}
}