Write Java Program Displays Following Gui Caculator Number 1 Number 2result Add Ubtract Mu Q37037198

byjava, without using listeners
Write a Java program that displays the following GUI: Caculator Number 1 Number 2Result Add ubtract MultiplyDivideWrite a Java program that displays the following GUI: Caculator Number 1 Number 2Result Add ubtract MultiplyDivide Show transcribed image text Write a Java program that displays the following GUI: Caculator Number 1 Number 2Result Add ubtract MultiplyDivide


Solution


GUI without Listeners

import javax.swing.*;

public class CalculatorGUI
{
public static void main(String args[])
{
JFrame f1=new JFrame(“Calculator”);
f1.setLayout(null);
JLabel ln1=new JLabel(“Number1”);
JLabel ln2=new JLabel(“Number2”);
JLabel lr=new JLabel(“Result”);
JTextField tn1=new JTextField();
JTextField tn2=new JTextField();
JTextField tResult=new JTextField();
JButton btnAdd=new JButton(“Add”);
JButton btnSub=new JButton(“Subtract”);
JButton btnMult=new JButton(“Multiply”);
JButton btnDiv=new JButton(“Divide”);
ln1.setBounds(5,5,60,30);
tn1.setBounds(70,5,60,30);
ln2.setBounds(140,5,60,30);
tn2.setBounds(200,5,60,30);
lr.setBounds(270,5,60,30);
tResult.setBounds(315,5,60,30);
tResult.setEditable(false);
btnAdd.setBounds(25,50,60,30);
btnSub.setBounds(100,50,90,30);
btnMult.setBounds(200,50,90,30);
btnDiv.setBounds(300,50,70,30);
f1.add(ln1);
f1.add(ln2);
f1.add(lr);
f1.add(tn1);
f1.add(tn2);
f1.add(tResult);
f1.add(btnAdd);
f1.add(btnSub);
f1.add(btnMult);
f1.add(btnDiv);
f1.setVisible(true);
f1.setSize(410,130);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

t PS C: UsersluserDesktop> javac CalculatorGUI. java PS C:UsersuserDesktop java CalculatorGUI Calculatr Multiply Activat

t

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.