Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA (not Javascript): Write a program that displays a numeric keypad that mi

ID: 3666065 • Letter: I

Question

In JAVA (not Javascript):

Write a program that displays a numeric keypad that might appear on a phone. Above the keypad buttons, show a label that displays the numbers once they are picked.

To the right of the keypad buttons, include another button to clear the display. Use a border layout to manage the keypad buttons. Put a border around the keypad buttons

to group them visually, and a border around the display too.

Here is the code to get you started, and a picture of what the code should roughly display once you run it:

Please post a picture of the code as well, so there are no spacing issues. Also please post a picture of the outcome once you run the code.

The program that I am using is JGrasp. Thanks.

NumericKeypad.java Author: Lewis/Loftus Numeric Keypad // Solution to Programming Project 7.13 import Javax. 3wing.uErame public class NumericKeypad // Creates and presents the program frame. public static void main (String [] args) JFrame quoteFrame new JFrame ("Numeric Keypad"); quoteFrame.setDefaultcloseoperation (JErame .EXIT_ON_CLOSE) quoteFrame.getContentPane () .add (new NumericKeypadPanel )) quoteFrame.pack ); quoteFrame.setVisible (true): Clear

Explanation / Answer

import javax.swing.*;
import java.awt.*;

public class KeyPad extends JFrame
{

public static void main (String[] args)
{
KeyPad = new KeyPad();
}


public KeyPad()
{
setTitle("Numeric Keypad");
setSize(350,450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridLayout(4,3,0,0));

JButton button1= new JButton("7");
JButton button2= new JButton("8");
JButton button3= new JButton("9");
JButton button4= new JButton("4");
JButton button5= new JButton("5");
JButton button6= new JButton("6");
JButton button7= new JButton("1");
JButton button8= new JButton("2");
JButton button9= new JButton("3");
JButton button0= new JButton("0");
JButton buttonstar= new JButton("*");
JButton buttonhash= new JButton("#");
JButton buttonClear= new JButton("Clear");

JTextField x = new JTextField(" ");

add(button1);
add(button2);
add(button3);
add(button4);
add(button5);
add(button6);
add(button7);
add(button8);
add(button9);
add(buttonstar);
add(button0);
add(buttonhash);
add(buttonclear);

setVisible(true);


}
  
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = username_field.getText(); // get text from button
x.setText("" + name); // set text in the textfield

}
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
button4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
button5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
button6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
  x.setText("" + name);
}
});
button7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
button8.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
button9.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
  x.setText("" + name);
}
});
button0.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
buttonstar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
x.setText("" + name);
}
});
buttonhash.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
name = e.getText();
  x.setText("" + name);
}
});
buttonclear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
x.setText(" " );   
});
  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote