Professional Documents
Culture Documents
import java.awt.*;
import java.awt.event.*;
Button btn1,btn2,btn3;
TextField tf1,tf2;
public EventDemo1()
setLayout(new FlowLayout());
btn1=new Button("Square");
btn2=new Button("Cube");
tf1=new TextField(15);
tf2=new TextField(15);
tf2.setEditable(false);
add(tf1);
add(btn1);
add(btn2);
add(btn3);
add(tf2);
btn1.addFocusListener(new InnerFocus());
btn1.addActionListener(new InnerSquare());
btn2.addFocusListener(new InnerFocus());
btn2.addActionListener(new InnerCube());
btn3.addFocusListener(new InnerFocus());
btn3.addActionListener(new InnerSqRoot());
}//end of constructor
Object ob=fe.getSource();
if(ob==btn1)
btn1.setBackground(Color.red);
btn2.setBackground(Color.yellow);
btn3.setBackground(Color.yellow);
if(ob==btn2)
btn2.setBackground(Color.red);
btn1.setBackground(Color.yellow);
btn3.setBackground(Color.yellow);
if(ob==btn3)
btn3.setBackground(Color.red);
btn2.setBackground(Color.yellow);
btn1.setBackground(Color.yellow);
}//end of inner1
int n=Integer.parseInt(tf1.getText());
int s=n*n;
tf2.setText(""+s);
}//end of event()
}//end of inner2
int n=Integer.parseInt(tf1.getText());
int c=n*n*n;
tf2.setText(""+c);
}//end of event()
}//end of inner3
int n=Integer.parseInt(tf1.getText());
double sq=Math.sqrt(n);
tf2.setText(""+sq);
}//end of event()
}//end of inner4
{
EventDemo1 fr=new EventDemo1();
fr.setSize(300,300);
fr.setVisible(true);
}//end of class