.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Jean Paul
SP
satyapriyanayak
Ashutosh Jha
Simon Robert VoIP

Home >> Code Snippets >> OOPS >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Applet using arithmetic calculation.

Posted By:laptop charles       Posted Date: June 30, 2010    Points: 10    Category: OOPS    URL: http://www.dotnetspark.com  

Arithmetic operation
 

It contain four operation.
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class app2 extends Applet implements ActionListener
{
	Label l1,l2,l3;
        TextField t1,t2,t3;
        Button b1,b2,b3,b4;
	public void init()
	{
 	 l1=new Label("ENTER THE NUMBER1");
	 l2=new Label("ENTER THE NUMBER2");
         l3=new Label("RESULT");
         t1=new TextField(20);
	 t2=new TextField(20);
	 t3=new TextField(20);
         b1=new Button("add");
	 b2=new Button("multi");  
	 b3=new Button("divid"); 
	 b4=new Button("sub");
        add(l1);
        add(t1);
	add(l2);
	add(t2);
	add(l3);
	add(t3);
	add(b1);
	add(b2);
	add(b3);
	add(b4);
        b1.addActionListener(this);
 	b2.addActionListener(this);
	b3.addActionListener(this);
	b4.addActionListener(this);
       }
    public void actionPerformed(ActionEvent e)
    { 
      
	Object obj=e.getSource();
         if(obj==b1)
          {
		int a=Integer.parseInt(t1.getText());
		int b= Integer.parseInt(t2.getText());
		int c=a+b;
           	t3.setText(c+"");
	   }
	   else if(obj==b2)
		{
		int a=Integer.parseInt(t1.getText());
		int b= Integer.parseInt(t2.getText());
		int c=a*b;
           	t3.setText(c+"");		
		}
	    else if(obj==b3)
		{
		int a=Integer.parseInt(t1.getText());
		int b= Integer.parseInt(t2.getText());
		int c=a/b;
           	t3.setText(c+"");		
		}
	    else if(obj==b4)
		{
		int a=Integer.parseInt(t1.getText());
		int b= Integer.parseInt(t2.getText());
		int c=a-b;
           	t3.setText(c+"");		
		}
	}
}
  
/*
*/

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend