Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Example Java Swing Calculator In Swing

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

13 comments so far (post your own) View All Comments Latest 10 Comments:

calculator program was gr4eat thanq very much.........

Posted by 9021yhb on Monday, 06.7.10 @ 17:14pm | #97418

please give code of calculator that calculate percentage

Posted by sonali on Saturday, 04.3.10 @ 11:46am | #96079

Thanks you .
I seek java perfect reference.
I am very interesting
to Java language programming.

Posted by kia on Monday, 11.2.09 @ 17:25pm | #92271

can u please expalin each functions of the code of the SwingCalculator

Posted by MAY on Friday, 10.9.09 @ 07:32am | #91577

public class CalculatorClass {
public static void main(String[] args) {
MainMethodClass FT = new MainMethodClass();
FT.necessary();
}
}
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.*;

class MainMethodClass extends JFrame implements ActionListener{

public MainMethodClass(){
}
JButton zeroButton, oneButton, twoButton, threeButton, fourButton, fiveButton, sixButton, sevenButton, eightButton, nineButton ;
JButton addButton, multiplyButton, subButton, divButton, equalsButton , clsButton;
JTextField digitField ;
int operator;
boolean a, b , c, d;
void necessary(){

Container Con = getContentPane();
setLayout(new FlowLayout());
setTitle("Simple Calculator");

// Initializing Buttons & TextBoxes.

digitField = new JTextField(10);
digitField.setSize(50, 20);
Con.add(digitField);

sevenButton = new JButton("7");
sevenButton.addActionListener(this);
Con.add(sevenButton);

eightButton = new JButton("8");
eightButton.addActionListener(this);
Con.add(eightButton);

nineButton = new JButton("9");
nineButton.addActionListener(this);
Con.add(nineButton);

fourButton = new JButton("4");
fourButton.addActionListener(this);
Con.add(fourButton);

fiveButton = new JButton("5");
fiveButton.addActionListener(this);
Con.add(fiveButton);

sixButton = new JButton("6");
sixButton.addActionListener(this);
Con.add(sixButton);

oneButton = new JButton("1");
oneButton.addActionListener(this);
Con.add(oneButton);

twoButton = new JButton("2");
twoButton.addActionListener(this);
Con.add(twoButton);

threeButton = new JButton("3");
threeButton.addActionListener(this);
Con.add(threeButton);

addButton = new JButton("+");
addButton.addActionListener(this);
Con.add(addButton);

multiplyButton = new JButton("x");
multiplyButton.addActionListener(this);
Con.add(multiplyButton);

subButton = new JButton("-");
subButton.addActionListener(this);
Con.add(subButton);

zeroButton = new JButton("0");
zeroButton.addActionListener(this);
Con.add(zeroButton);

equalsButton = new JButton("=");
equalsButton.addActionListener(this);
Con.add(equalsButton);

divButton = new JButton("/");
divButton.addActionListener(this);
Con.add(divButton);

clsButton = new JButton("C");
clsButton.addActionListener(this);
// clsButton.setSize(100, 100);
Con.add(clsButton);

setVisible(true);
setSize(172,247);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
System.out.println(""+e.getActionCommand());

if(e.getActionCommand()== "1" || e.getActionCommand()=="2" || e.getActionCommand()== "3" || e.getActionCommand()=="4" || e.getActionCommand()=="5" || e.getActionCommand()=="6" || e.getActionCommand()=="7" || e.getActionCommand()=="8" || e.getActionCommand()=="9" || e.getActionCommand()=="0"){
digitField.setText(digitField.getText()+e.getActionCommand());
}
else if(e.getActionCommand()=="+"){
operator = Integer.parseInt(digitField.getText());
a = true;
digitField.setText("");

}else if(e.getActionCommand()=="-"){
operator = Integer.parseInt(digitField.getText());
b = true;
digitField.setText("");
}else if(e.getActionCommand()=="x"){
operator = Integer.parseInt(digitField.getText());
c = true;
digitField.setText("");
}
else if(e.getActionCommand()=="/"){
operator = Integer.parseInt(digitField.getText());
d = true;
digitField.setText("");
}else if(e.getActionCommand()=="="){
if(a){
int a =operator + Integer.parseInt(digitField.getText());
digitField.setText(""+a);
}
else if(b){
int b =operator - Integer.parseInt(digitField.getText());
digitField.setText(""+b);
}
else if(c){
int c = operator * Integer.parseInt(digitField.getText());
digitField.setText(""+c);
}
else if(d){
int d = operator / Integer.parseInt(digitField.getText());
digitField.setText(""+d);
}

}
else if(e.getActionCommand()=="C"){
digitField.setText("");
}
}
}

Posted by KHURAM SHAHZAD on Monday, 05.25.09 @ 20:35pm | #88017

In this code errors occured like class or Interface ecpected provide error free code

Posted by Gagnesh on Wednesday, 05.20.09 @ 10:43am | #87842

help me! pogram colculator in builder c++

Posted by eky on Saturday, 04.25.09 @ 13:14pm | #87127

Thanks a lot.......... It was a lot useful........

Posted by Charu on Monday, 04.20.09 @ 15:39pm | #86951

what is the use the equals in this statement:
if (key.equals)???

Posted by stella on Sunday, 03.15.09 @ 23:34pm | #85874

what will i do to debug that code

Posted by JOnathan on Thursday, 02.12.09 @ 05:54am | #84759

Oh thats right... it sucks balls

Posted by fuck java on Monday, 02.2.09 @ 04:35am | #84401

why there is no html code?

Posted by shelby on Monday, 12.15.08 @ 04:01am | #82775

Thanx For Coding calculator
it is very usefull for
me THANXXXXXXXXXXXXXXX

Posted by Harshad on Wednesday, 12.10.08 @ 04:27am | #82598

Ask programming questions?

 

 

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.