Question: This is Java. I am looking for help with this program right now it is a basic key pad but I am looking to make

This is Java.

I am looking for help with this program right now it is a basic key pad but I am looking to make it into a calculator that adds and subtracts.

This is the project requirments

Use abstract methods

Create and use a 2D array if you can in your project.

You are to create an admin area to your site that is password protected and allows certain access to users based on their type (paid or not paid).

You should implement and use your own programmatic interface (one you create).

Add more end-user interaction in your graphical user interface. a. Use either KeyListener or MouseListener

Thanks for the help

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; import javax.swing.*;

public class keypad extends JPanel implements ActionListener{ JLabel display; JButton numberbut; JButton clearbut; String displaypanel = ""; String[] numbers = {"1","2","3","4","5","6","7","8","9","*","0","#"}; ArrayList buttonarray;

public keypad(Container panel) { panel.setPreferredSize(new Dimension(320, 335)); display = new JLabel(displaypanel); display.setPreferredSize(new Dimension(320, 25)); display.setBorder(BorderFactory.createLoweredBevelBorder()); panel.add(display, BorderLayout.PAGE_START); buttonarray = new ArrayList(12); JPanel numberpanel = new JPanel(); numberpanel.setLayout(new GridLayout(4,3,0,0)); numberpanel.setPreferredSize(new Dimension(320,260)); for (int i = 0; i < numbers.length; i++) { numberbut = new JButton(numbers[i]); buttonarray.add(numberbut); } for (int n = 0; n < buttonarray.size(); n++){ buttonarray.get(n).addActionListener(this); numberpanel.add(buttonarray.get(n)); } numberpanel.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.black)); panel.add(numberpanel, BorderLayout.LINE_END); clearbut = new JButton("Clear"); clearbut.setPreferredSize(new Dimension(320, 30)); clearbut.addActionListener(this); panel.add(clearbut, BorderLayout.PAGE_END); } public void actionPerformed(ActionEvent e){ String textThere = display.getText(); String additionalText = ""; for (int a = 0; a < buttonarray.size(); a++){ if (e.getSource().equals(buttonarray.get(a))){ additionalText = buttonarray.get(a).getText(); } } if (e.getSource().equals(clearbut)){ textThere = ""; } display.setText(textThere.concat(additionalText)); } public static void main(String[] args){ JFrame frame = new JFrame("Keypad"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new keypad(frame)); frame.pack(); frame.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!