Perdonami ma mi dà due errori col codice che hai postato tu e sono i seguenti:

codice:
display cannot be resolved e

The method getText() is undefined for the type Object
ecco il codice che ho ora:

codice:
import javax.swing.*;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class MyButton extends JPanel {
	private JButton pulsante;
	public MyButton(String testo) {
		setLayout( new GridLayout(1, 1) );
		setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
		pulsante = new JButton(testo);
		pulsante.addActionListener(new MyListener());
		add(pulsante);
	}
	
    private class MyListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
                display.setText(e.getSource().getText());
        }
    }
}