You need an actionlistener..
I edited your code so that button 1 will work.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator extends JFrame{
JPanel NumberPanel = new JPanel();
ButtonHandler handler = new ButtonHandler();
JButton button;
JTextArea textArea;
Calculator(){
JPanel AllPanel = new JPanel();
AllPanel.setBorder(BorderFactory.createTitledBorder("Simple Calculator"));
getContentPane().add(AllPanel);
AllPanel.setLayout(null);
button = new JButton("1");
button.setBounds(10, 129, 89, 23);
button.addActionListener(handler);
AllPanel.add(button);
JButton button_1 = new JButton("2");
button_1.setBounds(109, 129, 89, 23);
AllPanel.add(button_1);
JButton button_2 = new JButton("3");
button_2.setBounds(208, 129, 89, 23);
AllPanel.add(button_2);
JButton button_3 = new JButton("4");
button_3.setBounds(10, 95, 89, 23);
AllPanel.add(button_3);
JButton button_4 = new JButton("5");
button_4.setBounds(109, 95, 89, 23);
AllPanel.add(button_4);
JButton button_5 = new JButton("6");
button_5.setBounds(208, 95, 89, 23);
AllPanel.add(button_5);
JButton button_6 = new JButton("7");
button_6.setBounds(10, 61, 89, 23);
AllPanel.add(button_6);
JButton button_7 = new JButton("8");
button_7.setBounds(109, 61, 89, 23);
AllPanel.add(button_7);
JButton button_8 = new JButton("9");
button_8.setBounds(208, 61, 89, 23);
AllPanel.add(button_8);
JButton button_9 = new JButton("0");
button_9.setBounds(109, 163, 89, 23);
AllPanel.add(button_9);
JButton btnClear = new JButton("Clear");
btnClear.setBounds(298, 163, 89, 23);
AllPanel.add(btnClear);
JButton btnAdd = new JButton("Add");
btnAdd.setBounds(298, 129, 89, 23);
AllPanel.add(btnAdd);
JButton btnSub = new JButton("Sub");
btnSub.setBounds(298, 95, 89, 23);
AllPanel.add(btnSub);
textArea = new JTextArea();
textArea.setBounds(43, 29, 253, 22);
AllPanel.add(textArea);
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == button)
{
textArea.insert("1",0);
}
}
}
public static void main (String [] arg){
JFrame frame = new Calculator();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setSize(400,250);
frame.setResizable(false);
}
}