/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication17;
/**
*
* @author gaurav
*/import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class JavaApplication17 extends Applet implements ActionListener {
Button sum,reset;
Label input1,input2,sum1;
TextField t1,t2,t3;
public void init()
{
setLayout(null);
Label input1=new Label("value1");
Label input2=new Label("value2");
Label sum1=new Label("sum");
input1.setBackground(Color.ORANGE); input2.setBackground(Color.orange); sum1.setBackground(Color.orange);
t1=new TextField();
t2=new TextField();
add(t1);
add(t2); t1.setBackground(Color.LIGHT_GRAY); t2.setBackground(Color.LIGHT_GRAY);
t1.reshape(200,100,50,20);
t2.reshape(200,200,50,20);
add(input1);
add(input2);add(sum1);
input1.reshape(100, 100, 50,20);
input2.reshape(100, 200, 50,20);
sum1.reshape(100,400,50,10);t3=new TextField();add(t3);t3.reshape(200,400,50,20); t3.setBackground(Color.MAGENTA);
sum=new Button("sum");add(sum);
sum.reshape(100,300,40,40);
reset=new Button("reset");
add(reset); sum.setBackground(Color.gray); reset.setBackground(Color.gray);
reset.reshape(200,300,40,40);
sum.addActionListener(this);
reset.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==sum){
String a=t1.getText();
String b=t2.getText();
int x=Integer.parseInt(b);int y=Integer.parseInt(a);
int c=x+y;
System.out.println(c);
t3.setText(String.valueOf(c));
}
else if(ae.getSource()==reset)
{
t3.setText(" ");t1.setText(" ")
;t2.setText(" ");
}
}
}
No comments:
Post a Comment