sorry for the poorly worded question. I was working on a java swing project to recreate a phone dialer but for some reason, I can't figure out why 'Buttons(digits of phonenumber) are not being displayed on the JFrame. When I run the program, it displays JFrame with a red background but without the numbers or the dial buttons. If someone can explain it at a beginner level, that would be appreciated.
enter code hereimport javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class phoneDialer implements ActionListener {
JButton zeroButton;
JButton oneButton;
JButton twoButton;
JButton threeButton;
JButton fourButton;
JButton fiveButton;
JButton sixButton;
JButton sevenButton;
JButton eightButton;
JButton nineButton;
JButton dashButton;
JButton dialButton;
String DigitHolder = ("");
String input;
JFrame myFrame;
JPanel myPanel;
JPanel digitPanel;
JPanel buttonPanel;
JLabel myLabel;
JTextField display;
GridLayout myGridLayout;
public static void main(String[] args) {
new phoneDialer();
}
public phoneDialer() {
myFrame = new JFrame();
myPanel = new JPanel();
digitPanel = new JPanel();
buttonPanel = new JPanel();
myFrame.setContentPane(myPanel);
myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS));
myPanel.setLayout(new BorderLayout(5, 10));
myFrame.setLayout(new BorderLayout());
myLabel = new JLabel("phoneDialer");
display = new JTextField(20);
// topPanel.setLayout(new FlowLayout());
myLabel = new JLabel("Enter the number to dial");
myPanel.add(myLabel);
myGridLayout = new GridLayout(4, 3, 5, 5);
oneButton = new JButton("1");
oneButton.addActionListener(this);
twoButton = new JButton("2");
twoButton.addActionListener(this);
threeButton = new JButton("3");
threeButton.addActionListener(this);
fourButton = new JButton("4");
fourButton.addActionListener(this);
fiveButton = new JButton("5");
fiveButton.addActionListener(this);
sixButton = new JButton("6");
sixButton.addActionListener(this);
sevenButton = new JButton("7");
sevenButton.addActionListener(this);
eightButton = new JButton("8");
eightButton.addActionListener(this);
nineButton = new JButton("9");
nineButton.addActionListener(this);
zeroButton = new JButton("0");
zeroButton.addActionListener(this);
dashButton = new JButton("-");
dashButton.addActionListener(this);
dialButton = new JButton("Dial");
dialButton.addActionListener(this);
myFrame.setLayout(new BorderLayout());
// myFrame.add(myPanel,BorderLayout.NORTH);
myFrame.add(buttonPanel, BorderLayout.CENTER);
myFrame.add(digitPanel, BorderLayout.SOUTH);
myPanel.setLayout(new BorderLayout());
myPanel.add(myLabel, BorderLayout.NORTH);
myPanel.add(display, BorderLayout.CENTER);
myPanel.setBackground(Color.RED);
buttonPanel.setLayout(new FlowLayout());
// buttonPanel.add(redialButton);
// sendButton.addActionListener(new SendButtonListener());
// clearButton.addActionListener(new ClearButtonListener());
// endButton.addActionListener(new EndButtonListener());
// redialButton.addActionListener(new RedialButtonListener());
buttonPanel.setBackground(Color.BLUE);
digitPanel.setLayout(new GridLayout(4, 3));
digitPanel.add(oneButton);
digitPanel.add(twoButton);
digitPanel.add(threeButton);
digitPanel.add(fourButton);
digitPanel.add(fiveButton);
digitPanel.add(sixButton);
digitPanel.add(sevenButton);
digitPanel.add(eightButton);
digitPanel.add(nineButton);
digitPanel.add(zeroButton);
digitPanel.add(dashButton);
// myFrame.add(myPanel, BorderLayout.CENTER);
// south status panel
myFrame.setTitle("Phone Dilaer");
myFrame.setSize(200, 250);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setVisible(true);
myPanel.add(digitPanel);
myPanel.add(buttonPanel);
}
public void actionPerformed(ActionEvent event) {
input = display.getText();
if (event.getSource() == oneButton) {
display.setText("1");
} else if (event.getSource() == twoButton) {
display.setText("2");
} else if (event.getSource() == threeButton) {
display.setText("3");
} else if (event.getSource() == fourButton) {
display.setText("4");
} else if (event.getSource() == fiveButton) {
display.setText("5");
} else if (event.getSource() == sixButton) {
display.setText("6");
} else if (event.getSource() == sevenButton) {
display.setText("7");
} else if (event.getSource() == eightButton) {
display.setText("8");
} else if (event.getSource() == nineButton) {
display.setText("9");
} else if (event.getSource() == zeroButton) {
display.setText("0");
} else if (event.getSource() == dashButton) {
display.setText("*");
}
}
}