Create Calculator in java through java programming

Create Calculator in java through java programming. How to create a calculator through java programming? To create a program for calculator using java language is bit tough. but from elmseekho.com you can learn that how can we create a program of calculator creation.

Here is complete verified coding for creating calculator. You just have to run this coding in your command prompt (cmd) using Java development kit (jdk) 1.6 or more.

Here is also different java and asp.net programs like:

  1. How to connect java with database|Using JDBC-ODBC Connection string
  2. How to Create combo box in java|Complete Coding
  3. Java program to calculate Age from Date of birth
  4. How to create a Recruitment or job announcement page in asp.net | Complete front end designing and backend coding
  5. How to Add multiple textbox values and showing their sum
  6. Employee Registration form | Creation of Registration form in visual studio using c# and asp.net
  7. How add new webpage in a website using C#, asp.net in visual studio.
  8. How to create login page using asp.net and C#
Create Calculator through java programming
Create Calculator in java through java programming

Complete Java Program to create calculator in java.
import java.awt.;
import java.awt.event.;

class calframe extends Frame implements ActionListener
{
int x,y,op;

TextField txt;
Label lb;

String value1,value2;

Button decbt17,rembt18,offbt19,onbt20,ninebt1, eightbt2, sevenbt3, ACbt4, sixbt5, fivebt6, fourbt7, dividbt8, threebt9, twobt10, onebt11, multibt12,
zerobt13, equalbt14, addbt15,subbt16;

calframe( )
{super(” KK-328A”);
setBounds(200,100,270,370);
super.setFont(new Font(“Times New Roman”,Font.BOLD,12));
addWindowListener(new WindowAdapter( )
{
public void windowClosing(WindowEvent we)
{
dispose();
}
});

setLayout(null);

txt=new TextField(40);
txt.setFont(new Font(“Times New Roman”, Font.BOLD,36));
txt.setBounds(30,60,210,50);

lb=new Label(“”);
lb.setBounds(10,60,10,10);
lb.setFont(new Font(“Times New Roman”,Font.BOLD,12));

decbt17=new Button(“.”);
decbt17.setBounds(20,140,50,25);
decbt17.addActionListener(this);

rembt18=new Button(“%”);
rembt18.setBounds(80,140,50,25);
rembt18.addActionListener(this);

offbt19=new Button(“off”);
offbt19.setBounds(140,140,50,25);
offbt19.addActionListener(this);

onbt20=new Button(“on”);
onbt20.setBounds(200,140,50,25);
onbt20.addActionListener(this);

sevenbt3=new Button(“7”);
sevenbt3.setBounds(20,180,50,25);
sevenbt3.addActionListener(this);

eightbt2=new Button(“8”);
eightbt2.setBounds(80,180,50,25);
eightbt2.addActionListener(this);

ninebt1=new Button(“9”);
ninebt1.setBounds(140,180,50,25);
ninebt1.addActionListener(this);

ACbt4=new Button(“AC”);
ACbt4.setBounds(200,180,50,25);
ACbt4.addActionListener(this);

fourbt7=new Button(“4”);
fourbt7.setBounds(20,220,50,25);
fourbt7.addActionListener(this);

fivebt6=new Button(“5”);
fivebt6.setBounds(80,220,50,25);
fivebt6.addActionListener(this);

sixbt5=new Button(“6”);
sixbt5.setBounds(140,220,50,25);
sixbt5.addActionListener(this);

dividbt8=new Button(“/”);
dividbt8.setBounds(200,220,50,25);
dividbt8.addActionListener(this);

onebt11=new Button(“1”);
onebt11.setBounds(20,260,50,25);
onebt11.addActionListener(this);

twobt10=new Button(“2”);
twobt10.setBounds(80,260,50,25);
twobt10.addActionListener(this);

threebt9=new Button(“3”);
threebt9.setBounds(140,260,50,25);
threebt9.addActionListener(this);

multibt12=new Button(“*”);
multibt12.setBounds(200,260,50,25);
multibt12.addActionListener(this);

zerobt13=new Button(“0”);
zerobt13.setBounds(20,300,50,25);
zerobt13.addActionListener(this);

equalbt14=new Button(“=”);
equalbt14.setBounds(80,300,50,25);
equalbt14.addActionListener(this);

addbt15=new Button(“+”);
addbt15.setBounds(140,300,50,25);
addbt15.addActionListener(this);

subbt16=new Button(“-“);
subbt16.setBounds(200,300,50,25);
subbt16.addActionListener(this);

add(txt);
add(lb);
add(ninebt1);
add(eightbt2);
add(sevenbt3);
add(ACbt4);
add(sixbt5);
add(fivebt6);
add(dividbt8);
add(fourbt7);
add(threebt9);
add(twobt10);
add(onebt11);
add(multibt12);
add(zerobt13);
add(equalbt14);
add(addbt15);
add(subbt16);
add(decbt17);
add(rembt18);
add(offbt19);
add(onbt20);

value1=””;
value2=””;
op=0;
setVisible(true);

}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource()==ninebt1)
{
value1+=”9″;
txt.setText(value1);
}
if (ae.getSource()==eightbt2)
{
value1+=”8″;
txt.setText(value1);
}
if (ae.getSource()==sevenbt3)
{
value1+=”7″;
txt.setText(value1);
}
if (ae.getSource()==ACbt4)
{
value1=””;
txt.setText(value1);
}
if (ae.getSource()==sixbt5)
{
value1+=”6″;
txt.setText(value1);
}
if (ae.getSource()==fivebt6)
{
value1+=”5″;
txt.setText(value1);
}
if (ae.getSource()==dividbt8)
{
x = Integer.parseInt(value1);
value1=””;
txt.setText(value1);
op=4;
}
if (ae.getSource()==fourbt7)
{
value1+=”4″;
txt.setText(value1);
}
if (ae.getSource()==threebt9)
{
value1+=”3″;
txt.setText(value1);
}
if (ae.getSource()==twobt10)
{
value1+=”2″;
txt.setText(value1);
}
if (ae.getSource()==onebt11)
{
value1+=”1″;
txt.setText(value1);
}
if (ae.getSource()==multibt12)
{
x = Integer.parseInt(value1);
value1=””;
txt.setText(value1);
op=3;
}
if (ae.getSource()==zerobt13)
{
value1+=”0″;
txt.setText(value1);
}
if (ae.getSource()==equalbt14)
{
int c;
if(op==1)
{
y=Integer.parseInt(value1);
c = x + y;
txt.setText(value2.valueOf(c));
}

if(op==2)
{
y=Integer.parseInt(value1);
c = x – y;
txt.setText(value2.valueOf(c));
}

if(op==3)
{
y=Integer.parseInt(value1);
c = x * y;
txt.setText(value2.valueOf(c));
}

if(op==4)
{
y=Integer.parseInt(value1);
c = x / y;
txt.setText(value2.valueOf(c));
}

}
if (ae.getSource()==addbt15)
{
x = Integer.parseInt(value1);
value1=””;
txt.setText(value1);
lb.setText(“+”);
op=1;
}
if (ae.getSource()==subbt16)
{
x = Integer.parseInt(value1);
value1=””;
txt.setText(value1);
op=2;
}
}
}

class calculate
{
public static void main(String str[])
{
calframe f=new calframe();
}
}

  1. How to connect java with database|Using JDBC-ODBC Connection string
  2. How to Create combo box in java|Complete Coding
  3. Java program to calculate Age from Date of birth
  4. How to create a Recruitment or job announcement page in asp.net | Complete front end designing and backend coding
  5. How to Add multiple textbox values and showing their sum
  6. Employee Registration form | Creation of Registration form in visual studio using c# and asp.net
  7. How add new webpage in a website using C#, asp.net in visual studio.
  8. How to create login page using asp.net and C#

Leave a Reply

Your email address will not be published. Required fields are marked *