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

Create a GUI program that will accept three integers say x, y and z, and then ve

ID: 3665256 • Letter: C

Question

Create a GUI program that will accept three integers say x, y and z, and then verify whether or not x * x + y * y = z * z. Save file as myGUI.java.

The GUI must be laid out as shown.

Assume that the user will enter three integers in the three text fields and none of the fields will be blank before Clicking “Yes or No” Button.

This is JAVA and should not be alot of lines of code...

141 Is x * x + y * y = z * z? Enter first integer (x): 4 Enter second integer (y):9 Enter third integer (z):15 Is x * x + y * y = z * z? : No Yes or No Exit

Explanation / Answer

Answer:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
class setCalculation extends JFrame implements ActionListener{
JLabel label1, label2, label3,label4;

JButton btnMultiply, btnExit;
JTextField txtField1, txtField2, txtField3,txtField4;

public setCalculation(){
setLayout(new GridLayout(5,2));
setTitle("Simple Calculator using Swing");
  
label1 = new JLabel("Number 1 :",JLabel.RIGHT);
label2 = new JLabel("Number 2 :",JLabel.RIGHT);
label3 = new JLabel("Number 3 :",JLabel.RIGHT);
label4=new JLabel("Is x * x + y * y = z * z :",JLabel.RIGHT);
  
btnMultiply = new JButton("Yes or No");
btnExit = new JButton("Exit");
  

  
btnMultiply.addActionListener(this);
btnExit.addActionListener(this);
  
txtField1 = new JTextField();
txtField2 = new JTextField();
txtField3 = new JTextField();
txtField4=new JTextField();

add(label1,0);
add(txtField1);
add(label2);
add(txtField2);
add(label3);
add(txtField3);
add(label4);
add(txtField4);
add(btnMultiply);
add(btnExit);
}



public void actionPerformed(ActionEvent event){
String option = event.getActionCommand();
  
int num1, num2, num3 = 0;
int p,q;
num1 = Integer.parseInt(txtField1.getText());
num2 = Integer.parseInt(txtField2.getText());
num3 = Integer.parseInt(txtField3.getText());
p=num3*num3 ;
q=num1 *num1+ num2*num2;
System.out.println(p);
System.out.println(q);

if(option.equals("Yes or No")&&(p==q))

       txtField4.setText("Yes");
      

else if(option.equals("Exit")){
txtField1.setText("");
txtField2.setText("");
txtField3.setText("");
txtField4.setText("");
}
txtField4.setText("No");
  
}
  
}

public class Calculation{
public static void main(String args[]){
setCalculation demo = new setCalculation();
demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
demo.setVisible(true);
demo.setSize(300,500);
}
}