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

%25253Cp%25253EPlease%252520create%252520a%252520program%252520which%252520creat

ID: 3551236 • Letter: #

Question

%25253Cp%25253EPlease%252520create%252520a%252520program%252520which%252520creates%252520a%252520grid%252520of%252520buttons%252520on%252520a%252520GUI%25250Athat%252520will%252520allow%252520a%252520user%252520to%252520check%252520the%252520multpilication%252520of%2525202%25250Anumbers.%25253C%25252Fp%25253E%25250A%25253Cp%25253EStart%252520off%252520the%252520program%252520by%252520asking%252520the%252520user%252520how%252520many%252520rows%252520and%25250Acolums%252520should%252520be%252520on%252520the%252520GUI%252520by%252520entering%252520the%252520values%252520in%252520a%25250AshowMessageDialog().%25253C%25252Fp%25253E%25250A%25253Cp%25253E%25253Cbr%252520%25252F%25253E%25253C%25252Fp%25253E%25250A%25253Cp%25253E%25253Cbr%252520%25252F%25253E%25253C%25252Fp%25253E%25250A%25253Cp%25253EWhen%252520a%252520user%252520clicks%252520on%252520a%252520button%252520anywhere%252520on%252520the%252520grid%25252C%252520it%252520should%25250Adisplay%252520a%252520value%252520somewhere%252520on%252520the%252520GUI%252520of%252520the%252520computation.%25253C%25252Fp%25253E%25250A%25253Cp%25253ESo%252520just%252520press%252520one%252520button%252520to%252520perform%252520the%252520full%252520operation....%25253C%25252Fp%25253E%25250A%25253Cp%25253E%25253Cbr%252520%25252F%25253E%25253C%25252Fp%25253E%25250A%25253Cp%25253EUse%252520this%252520picture%252520as%252520a%252520reference...%25253C%25252Fp%25253E%25250A%25253Cp%25253E%25253Cbr%252520%25252F%25253E%25253C%25252Fp%25253E%25250A%25253Cp%25253E%25253Cimg%252520class%25253D%252522user-upload%252522%252520src%25253D%25250A%252522http%25253A%25252F%25252Fmedia.cheggcdn.com%25252Fmedia%2525252F045%2525252F0457e8bc-2408-48c9-b66f-0034b8971122%2525252FphptO7Eub.png%252522%252520%25252F%25253E%25253C%25252Fp%25253E%25250A

Explanation / Answer

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Appl extends JFrame implements ActionListener {

  

private static final long serialVersionUID = 1L;

  

JButton btn[][] = new JButton[10][10];

  

  

TextField txt=new TextField(15);

String text = "";

double int_number1 = 0;

double int_number2 = 0;

double result = 0;

  

public calculator() {

  

for (int i=0;i<10;i++)

for (int j=0;j<10;j++)

{

int num = (i+1)*(j+1);

JButton temp = new JButton(num+"");

btn[i][j] = temp;

}

JFrame frame = new JFrame("Multiplication Table");

frame.setSize(820,620);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setResizable(false);

frame.setVisible(true);

  

frame.setLayout(new BorderLayout());

  

//JPanel HeadPanel = new JPanel();

JPanel NumberPanel = new JPanel();

JPanel LabelPanel = new JPanel();

  

LabelPanel.setBackground(Color.WHITE);

//HeadPanel.setBackground(Color.BLUE);

  

NumberPanel.setLayout(new GridLayout(11,11));

LabelPanel.setLayout(new FlowLayout());

  

NumberPanel.add(new JLabel("$"));

for (int i=0;i<10;i++)

{

int num = i+1;

NumberPanel.add(new JLabel(num+""));

}

for (int i=0;i<10;i++)

{

int num = i+1;

NumberPanel.add(new JLabel(num+""));

for (int j=0;j<10;j++)

{

NumberPanel.add(btn[i][j]);

btn[i][j].addActionListener(this);

}

}

LabelPanel.add(new JLabel("NUMBER : "));

//LabelPanel.add(txt);

txt.setEditable(false);

frame.add(NumberPanel,BorderLayout.CENTER);

frame.add(LabelPanel,BorderLayout.SOUTH);

  

}

  

public void actionPerformed(ActionEvent e) {

  

for (int i=0;i<10;i++)

for (int j=0;j<10;j++)

if(e.getSource()==btn[i][j])

{

int result = (i+1)*(j+1);

text = i + " * " + j + " = " + result;

txt.setText(""+text);

break;

}

  

}

  

public static void main(String[] args) {

  

new Appl();

  

}

}