How to get the keypad numbers to display

I have the following code, but I am unable to get the numbers to display when they are clicked.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
 
 
public class celluar extends JFrame implements ActionListener{
    // creates borders for display
 
    public static void main(String[] args) {
	celluar c = new celluar();
    }
    public celluar() {
 
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JPanel panel = new JPanel();
	panel.setLayout(new GridLayout(4, 3));
 
	panel.setBackground(Color.GRAY);
 
	// creates and add buttons for keypad
 
	JButton b1 = new JButton("1");
	panel.add(b1);
	b1.addActionListener(this);
	b1.setActionCommand("1");
	b1.setBackground(Color.BLUE);
 
	JButton b2 = new JButton("2");
	panel.add(b2);
	b2.addActionListener(this);
	b2.setActionCommand("2");
	b2.setBackground(Color.BLUE);
 
	JButton b3 = new JButton("3");
	panel.add(b3);
	b3.addActionListener(this);
	b3.setActionCommand("3");
	b3.setBackground(Color.BLUE);
 
	JButton b4 = new JButton("4");
	panel.add(b4);
	b4.addActionListener(this);
	b4.setActionCommand("4");
	b4.setBackground(Color.BLUE);
 
	JButton b5 = new JButton("5");
	panel.add(b5);
	b5.addActionListener(this);
	b5.setActionCommand("5");
	b5.setBackground(Color.BLUE);
 
	JButton b6 = new JButton("6");
	panel.add(b6);
	b6.addActionListener(this);
	b6.setActionCommand("6");
	b6.setBackground(Color.BLUE);
 
	JButton b7 = new JButton("7");
	panel.add(b7);
	b7.addActionListener(this);
	b7.setActionCommand("7");
	b7.setBackground(Color.BLUE);
 
	JButton b8 = new JButton("8");
	panel.add(b8);
	b8.addActionListener(this);
	b8.setActionCommand("8");
	b8.setBackground(Color.BLUE);
 
	JButton b9 = new JButton("9");
	panel.add(b9);
	b9.addActionListener(this);
	b9.setActionCommand("9");
	b9.setBackground(Color.BLUE);
 
	JButton b10 = new JButton("*");
	panel.add(b10);
	b10.addActionListener(this);
	b10.setActionCommand("*");
	b10.setBackground(Color.BLUE);
 
	JButton b11 = new JButton("0");
	panel.add(b11);
	b11.addActionListener(this);
	b11.setActionCommand("0");
	b11.setBackground(Color.BLUE);
 
 
	JButton b12 = new JButton("#");
	panel.add(b12);
	b12.addActionListener(this);
	b12.setActionCommand("#");
	b12.setBackground(Color.BLUE);
 
 
 
 
 
	getContentPane().setLayout(new BorderLayout());
	getContentPane().add(panel,BorderLayout.CENTER);
 
	JTextField number = new JTextField();
	number.setColumns(15);
	getContentPane().add(number,BorderLayout.NORTH);
 
	pack();
	setVisible(true);
 
    }
 
    public void actionPerformed(ActionEvent e) {}
}

Open in new window

bdiddy05Asked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
 
 
public class celluar extends JFrame implements ActionListener{
    // creates borders for display
 
    JTextField number = new JTextField();

    public static void main(String[] args) {
        celluar c = new celluar();
    }
    public celluar() {
 
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 3));
 
        panel.setBackground(Color.GRAY);
 
        // creates and add buttons for keypad
 
        JButton b1 = new JButton("1");
        panel.add(b1);
        b1.addActionListener(this);
        b1.setActionCommand("1");
        b1.setBackground(Color.BLUE);
 
        JButton b2 = new JButton("2");
        panel.add(b2);
        b2.addActionListener(this);
        b2.setActionCommand("2");
        b2.setBackground(Color.BLUE);
 
        JButton b3 = new JButton("3");
        panel.add(b3);
        b3.addActionListener(this);
        b3.setActionCommand("3");
        b3.setBackground(Color.BLUE);
 
        JButton b4 = new JButton("4");
        panel.add(b4);
        b4.addActionListener(this);
        b4.setActionCommand("4");
        b4.setBackground(Color.BLUE);
 
        JButton b5 = new JButton("5");
        panel.add(b5);
        b5.addActionListener(this);
        b5.setActionCommand("5");
        b5.setBackground(Color.BLUE);
 
        JButton b6 = new JButton("6");
        panel.add(b6);
        b6.addActionListener(this);
        b6.setActionCommand("6");
        b6.setBackground(Color.BLUE);
 
        JButton b7 = new JButton("7");
        panel.add(b7);
        b7.addActionListener(this);
        b7.setActionCommand("7");
        b7.setBackground(Color.BLUE);
 
        JButton b8 = new JButton("8");
        panel.add(b8);
        b8.addActionListener(this);
        b8.setActionCommand("8");
        b8.setBackground(Color.BLUE);
 
        JButton b9 = new JButton("9");
        panel.add(b9);
        b9.addActionListener(this);
        b9.setActionCommand("9");
        b9.setBackground(Color.BLUE);
 
        JButton b10 = new JButton("*");
        panel.add(b10);
        b10.addActionListener(this);
        b10.setActionCommand("*");
        b10.setBackground(Color.BLUE);
 
        JButton b11 = new JButton("0");
        panel.add(b11);
        b11.addActionListener(this);
        b11.setActionCommand("0");
        b11.setBackground(Color.BLUE);
 
 
        JButton b12 = new JButton("#");
        panel.add(b12);
        b12.addActionListener(this);
        b12.setActionCommand("#");
        b12.setBackground(Color.BLUE);
 
 
 
 
 
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(panel,BorderLayout.CENTER);
 
        number.setColumns(15);
        getContentPane().add(number,BorderLayout.NORTH);
 
        pack();
        setVisible(true);
 
    }
 
    public void actionPerformed(ActionEvent e) {
          number.setText(number.getText()+e.getActionCommand());
    }
}
0
 
CEHJCommented:
>>public void actionPerformed(ActionEvent e) {}

As i mentioned in your previous question, your ActionListener is empty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.