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


Top 5 Contributors of the Month
david stephan

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

 Subscribe to Code Snippets

Java applet to add and subtract two value.

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

Add and subtract two values
 

It has used two label and two button and two textbox.
One button to add and other one is subtracter.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*
*/
 public class app3 extends Applet implements ActionListener
{
int c;
Label l1,l2,l3;
TextField text1,text2,text3;
Button button1,button2;

public void init()
{
l1 =new Label("a");
add(l1);

text1 = new TextField(20);
add(text1);

l2 =new Label("b");
add(l2);

text2 = new TextField(20);
add(text2);

l3 =new Label("total");
add(l3);

text3 = new TextField(20);
add(text3);

button1 =new Button("add");
button1.setBackground(Color.red);
add(button1);
button1.addActionListener(this);

button2 =new Button("sub");
button2.setBackground(Color.green);
add(button2);
button2.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
int a=Integer.parseInt(text1.getText());
int b=Integer.parseInt(text2.getText());


if(str.equals("button1"))
{
c=a+b;
text3.setText(""+c);
}
else 
{
c=a-b;
text3.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