


Hello friends For multidigit calculator code u can visit the follwowing link

Java Calculator Code and methods

import java.awt.*; import java.awt.event.*;
class AA implements ActionListener { Frame f; TextField tf;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,plush,minus,mul,div,equal,clear;
String s="";
int n,c;
AA()
{
f=new Frame("jamshjed");
tf=new TextField();
tf.setBounds(50,50,300,50);
b1=new Button("1");
b1.setBounds(50,150,50,50);
b1.addActionListener(this);
b2=new Button("2");
b2.setBounds(105,150,50,50);
b2.addActionListener(this);
b3=new Button("3");
b3.setBounds(160,150,50,50);b3.addActionListener(this);
b4=new Button("4");
b4.setBounds(215,150,50,50);b4.addActionListener(this);
b5=new Button("5");
b5.setBounds(270,150,50,50);b5.addActionListener(this);
b6=new Button("6");
b6.setBounds(50,230,50,50);b6.addActionListener(this);
b7=new Button("7");
b7.setBounds(105,230,50,50);b7.addActionListener(this);
b8=new Button("8");
b8.setBounds(160,230,50,50);b8.addActionListener(this);
b9=new Button("9");
b9.setBounds(215,230,50,50);b9.addActionListener(this);
b0=new Button("0");
b0.setBounds(270,230,50,50);b0.addActionListener(this);
plush=new Button("+");
plush.setBounds(50,310,160,50);plush.addActionListener(this);
minus=new Button("-");
minus.setBounds(215,310,105,50);minus.addActionListener(this);
mul=new Button("*");
mul.setBounds(50,390,50,50);mul.addActionListener(this);
equal=new Button("=");
equal.setBounds(105,390,50,50);equal.addActionListener(this);
div=new Button("/");
div.setBounds(160,390,50,50);div.addActionListener(this);
clear=new Button("c");
clear.setBounds(215,390,105,50);clear.addActionListener(this);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.add(b8);
f.add(b9);
f.add(b0);
f.add(plush);
f.add(minus);
f.add(mul);
f.add(equal);
f.add(div);
f.add(clear);
f.add(tf);
f.setSize(500,500);
f.setLayout(null);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("1"))
{
s=s+"1";
tf.setText(s);
}
if(e.getActionCommand().equals("2"))
{
s=s+"2";
tf.setText(s);
}
if(e.getActionCommand().equals("3"))
{
s=s+"3";
tf.setText(s);
}
if(e.getActionCommand().equals("4"))
{
s=s+"4";
tf.setText(s);
}
if(e.getActionCommand().equals("5"))
{
s=s+"5";
tf.setText(s);
}
if(e.getActionCommand().equals("6"))
{
s=s+"6";
tf.setText(s);
}
if(e.getActionCommand().equals("7"))
{
s=s+"7";
tf.setText(s);
}
if(e.getActionCommand().equals("8"))
{
s=s+"8";
tf.setText(s);
}
if(e.getActionCommand().equals("9"))
{
s=s+"9";
tf.setText(s);
}
if(e.getActionCommand().equals("0"))
{
s=s+"0";
tf.setText(s);
}
if(e.getActionCommand().equals("+"))
{
n=Integer.parseInt(tf.getText());
tf.setText("");
s="";
c=1;
}
if(e.getActionCommand().equals("-"))
{
n=Integer.parseInt(tf.getText());
tf.setText("");
s="";
c=2;
}
if(e.getActionCommand().equals("/"))
{
n=Integer.parseInt(tf.getText());
tf.setText("");
s="";
c=3;
}
if(e.getActionCommand().equals("*"))
{
n=Integer.parseInt(tf.getText());
tf.setText("");
s="";
c=4;
}
if(e.getActionCommand().equals("c"))
{
tf.setText("");
s="";
}
if(e.getActionCommand().equals("="))
{
if(c==1)
{
int j=Integer.parseInt(tf.getText());
int k=n+j;
String ss=String.valueOf(k);
tf.setText(ss);
}
if(c==2)
{
int j=Integer.parseInt(tf.getText());
int k=n-j;
String ss=String.valueOf(k);
tf.setText(ss);
}
if(c==3)
{
int j=Integer.parseInt(tf.getText());
int k=n/j;
String ss=String.valueOf(k);
tf.setText(ss);
}
if(c==4)
{
int j=Integer.parseInt(tf.getText());
int k=n*j;
String ss=String.valueOf(k);
tf.setText(ss);
}
}
}
public static void main(String... aa)
{
AA o=new AA();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.