15 June, 2012

Basic Arthimatic Operation



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ArthimaticOpration extends JFrame implements ActionListener
{
JTextField t1,t2,t3,t4,t5,t6 ;
public ArthimaticOpration()
{
setTitle("ArthimaticOpration For Add 2 Number");
setSize(290,240);
setLocation(400,250);
setLayout(new FlowLayout());

t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(15);
t4 = new JTextField(15);
t5 = new JTextField(15);
t6 = new JTextField(15);

JButton b = new JButton("ADD");
JButton b1 = new JButton("SUB");
JButton b2 = new JButton("MUL");
JButton b3 = new JButton("DIV");
JButton b4 = new JButton("OK");

add(t1);
add(t2);

add(b);
add(t3);

add(b1);
add(t4);

add(b2);
add(t5);

add(b3);
add(t6);

add(b4);

b.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}

public void actionPerformed (ActionEvent e)
{
int a = Integer.parseInt(t1.getText());
int b = Integer.parseInt(t2.getText());

int sum =a+b;
t3.setText(" " +sum);

int sub =a-b;
t4.setText(" " +sub);

double mul =a*b;
t5.setText(" " +mul);

int div =a/b;
int rem=a%b;
int r=(rem*10000)/b;
t6.setText(" " +div+"."+r);
}

public static void main (String[] args)
{
ArthimaticOpration c = new ArthimaticOpration();
c.setVisible(true);
}

}




No comments:

Post a Comment

Thank You !