java_program 10

 Practical Name: Write a java  program using swing to calculate simple arithmatic calculator

___________________________________________________________________________

 

import java.io.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

public class C_T_C extends JFrame implements ActionListener {

JLabel l1,l2,l3,l4,l5,l6;

JTextField tf1,tf2,tf3,tf4,tf5;

JButton cal,cle,clo;

public int tt,ii;

public C_T_C(){

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setResizable(false);

l1=new JLabel("Compund Intrest Calculator");

l1.setBounds(120,0,500,30);

l1.setFont(new Font("ariel",Font.BOLD,20));

add(l1);

l2=new JLabel("Principal Amount");

l2.setBounds(20,50,130,30);

l2.setFont(new Font("ariel",Font.BOLD,13));

add(l2);

tf1=new JTextField();

tf1.setBounds(160,50,300,30);

add(tf1);

l3=new JLabel("Intrest Rate (%)");

l3.setBounds(20,100,100,30);

add(l3);

tf2=new JTextField();

tf2.setBounds(160,100,50,30);

add(tf2);

l6=new JLabel("Time (Yrs)");

l6.setBounds(260,100,100,30);

add(l6);

tf3=new JTextField();

tf3.setBounds(330,100,130,30);

add(tf3);

l4=new JLabel("Total Amount");

l4.setBounds(20,150,100,30);

add(l4);

tf4=new JTextField(tt);

tf4.setBounds(160,150,150,30);

add(tf4);

l5=new JLabel("Intrest Amount");

l5.setBounds(20,200,100,30);

add(l5);

tf5=new JTextField(ii);

tf5.setBounds(160,200,200,30);

add(tf5);

cal=new JButton("Calculate");

cal.setBounds(20,250,100,30);

cal.addActionListener(this);

add(cal);

cle=new JButton("Clear");

cle.setBounds(190,250,100,30);

cle.addActionListener(this);

add(cal);

add(cle);

clo=new JButton("Close");

clo.setBounds(360,250,100,30);

clo.addActionListener(this);

add(clo);

setLayout(null); setBounds(550,100,500,350);

setVisible(true);}

public void actionPerformed(ActionEvent e){

int P=Integer.parseInt(tf1.getText());

int R=Integer.parseInt(tf2.getText());

int T=Integer.parseInt(tf3.getText());  int t=P*R*T/100;  int tt=t+P;

String nn="";

if (e.getSource()==cal){

tf5.setText(tf5.getText().concat(""+t));

tf4.setText(tf4.getText().concat(""+tt));   }

if (e.getSource()==cle){

tf1.setText("");



tf2.setText("");

tf3.setText("");

tf4.setText("");

tf5.setText("");}

if (e.getSource()==clo){

setDefaultCloseOperation(EXIT_ON_CLOSE);        }

}public static void main(String [] a){

new C_T_C();   }                }




Post a Comment

Previous Post Next Post