Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java Create a GUI application for a calculator that can perform log cal operations such as And, Or , Xor, Not, Shift Left, and
In java Create a GUI application for a calculator that can perform logcal operations such as And, Or Xor, Not, Shift Left, and Shift Right. The calculator includes buttons to plus buttons labeled A B C D E and F for entering a number in hexadecimal format. The user can select the input number radix from Binary, Decimal, or Hexadecimal from three radio buttons. If the Binary radio button is selected, only buttons and should be enabled and all the others should be disabled. if the Decimal radio button is selected, buttons labeled A B C D E and F should be disabled. Check the following sample layout of the project check the Microsoft Calculator application in programmer mode for more details
our professor gave this code as an example please dont copy paste the answers from chatgpt or other answers
User
class calculator extends JFrame implements ActionListener
create a frame
static JFrame f;
create a textfield
static JTextField l;
store oprerator and operands
String s s s;
default constrcutor
calculator
s s s;
f new JFramecalculator;
try
set look and feel
UIManager.setLookAndFeelUIManagergetSystemLookAndFeelClassName;
catch Exception e
System.err.printlnegetMessage;
create a object of class
create a textfield
l new JTextField;
set the textfield to non editable
lsetEditablefalse;
create number buttons and some operators
JButton b b b b b b b b b b ba bs bd bm be beq, beq;
create number buttons
b new JButton;
b new JButton;
b new JButton;
b new JButton;
b new JButton;
b new JButton;
b new JButton;
b new JButton;
b new JButton;
b new JButton;
equals button
beq new JButton;
create operator buttons
ba new JButton;
bs new JButton;
bd new JButton;
bm new JButton;
beq new JButtonC;
create button
be new JButton;
create a panel
JPanel p new JPanel;
add action listeners
bmaddActionListenerthis;
bdaddActionListenerthis;
bsaddActionListenerthis;
baaddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
baddActionListenerthis;
beaddActionListenerthis;
beq.addActionListenerthis;
beqaddActionListenerthis;
add elements to panel
paddl;
paddba;
paddb;
paddb;
paddb;
paddbs;
paddb;
paddb;
paddb;
paddbm;
paddb;
paddb;
paddb;
paddbd;
paddbe;
paddb;
paddbeq;
paddbeq;
set Background of panel
psetBackgroundColorGRAY;
add panel to frame
faddp;
fsetSize;
fshow;
main function
public void actionPerformedActionEvent e
String s egetActionCommand;
if the value is a number
if scharAt && scharAt scharAt
if operator is present then add to second operand
if sequals
s s s;
else
s s s;
set the value of text
lsetTexts s s;
else if scharAtC
clear the one letter
s s s;
set the value of text
lsetTexts s s;
else if scharAt
double te;
store the value in st
if sequals
te DoubleparseDoubles Double.parseDoubles;
else if sequals
te DoubleparseDoubles Double.parseDoubles;
else if sequals
te DoubleparseDoubles Double.parseDoubles;
else
te DoubleparseDoubles Double.parseDoubles;
set the value of text
lsetTexts s s te;
convert it to string
s Double.toStringte;
s s;
else
if there was no operand
if sequals sequals
s s;
else evaluate
else
double te;
store the value in st
if sequals
te DoubleparseDoubles Double.parseDoubles;
else if sequals
te DoubleparseDoubles Double.parseDoubles;
else if sequals
te DoubleparseDoubles Double.parseDoubles;
else
te DoubleparseDoubles Double.parseDoubles;
convert it to string
s Double.toStringte;
place the operator
s s;
make the operand blank
s;
set the value of text
lsetTexts s s;
import java.awt.event.;
import javax.swing.;
import java.awt.;
class Main
public static void mainString args
create a frame
calculator c new calculator
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started