Skip to main content

Calculator Program using jFrame

Calculator Program using jFrame

java swing calculator example
java jframe calculator source code
java code for simple calculator using gui
how to make a calculator in advance java using JFrame
simple calculator program in java using frame
simple calculator program in java source code
write a code to create simple calculator using swing component







import javax.swing.*;
import java.awt.event.*;
public class TextFieldExample extends JFrame implements ActionListener{
    JTextField tf1,tf2,tf3;
    JButton b1,b2;
//declaration of control

    TextFieldExample(){
        JFrame f= new JFrame("Button click demo");
//

        tf1=new JTextField();
        tf1.setBounds(50,50,150,20);

        tf2=new JTextField();
        tf2.setBounds(50,100,150,20);

        tf3=new JTextField();
        tf3.setBounds(50,150,150,20);
       tf3.setEditable(false);  


        b1=new JButton("+");
        b1.setBounds(50,200,50,50);

        b2=new JButton("-");
        b2.setBounds(120,200,50,50);

        b1.addActionListener(this);  // event handing power
        b2.addActionListener(this);


        f.add(tf1);f.add(tf2);f.add(tf3);f.add(b1);f.add(b2);

        f.setSize(300,300);
        f.setLayout(null);
        f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);

    }        
    public void actionPerformed(ActionEvent e) {
        String s1=tf1.getText();
        String s2=tf2.getText();
        int a=Integer.parseInt(s1);
        int b=Integer.parseInt(s2);
        int c=0;
        if(e.getSource()==b1){
            c=a+b;
        }else if(e.getSource()==b2){
            c=a-b;
        }
        String result=String.valueOf(c);
        tf3.setText(result);
    }
public static void main(String[] args) {
    new TextFieldExample();
} }






Labels

Show more

Popular posts from this blog

Java Program to delete record using JFrame and Prepaired Statement

Java Program to delete record using JFrame and Prepaired Statement Here is table Design  Create table demo using two column as id  and Dname , id is primary key  Program source code  +import javax.swing.*;   import java.awt.event.*;   import java.sql.*; public class FrameDelete extends JFrame implements ActionListener{       JTextField tf1,tf2,tf3;       JButton b1,b2;   JLabel l1,l2; Connection con;    PreparedStatement psmt;   int result; //declaration of control    FrameDelete(){           JFrame f= new JFrame("InsertDemo");   // l1=new JLabel("Enter RollNo"); l1.setBounds(150,10,150,50);         tf1=new JTextField();           tf1.setBounds(150,50,150,20);   tf3=new JTextField();           tf3.setBounds(1...

Basic java

java java java, learn java online free, classroom java tutorial, beginners java, java beginners, java programming,  basic java , basic java Tutorial,  basic java  Assignment           Hello friends ,       I am learning Basic java . my motive behind this blog is to help those want to learn Basic java online free of cost and grab each and every basic aspect of java programming .     you can find java tutorial from basic on this blog i will post each and every assignment of basic java with source code .          we will divide our course  in to Day work .          Let's start Day One  Basic Java Assignment for  Beginners      Basic Requirement to learn Java Programming Download following software             1. Text Editor (Notepad, Notepad++, Edit pad, Eclipse...