Java program for square root:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class SqRoot extends Frame implements ActionListener
{
TextField t1,t2;
Label l1,l2;
Button b1,b2;
SqRoot()
{
setVisible(true);
setTitle("Special Purpose Claculator");
setSize(400,400);
l1=new Label("Input no.");
l2=new Label("Output");
t1=new TextField(10);
t2=new TextField(10);
b1=new Button("Calculate");
b2=new Button("Clear");
b1.addActionListener(this);
b2.addActionListener(this);
Panel p1=new Panel( );
p1.setLayout(new GridLayout(2,2));
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
Panel p2=new Panel( );
p2.setLayout(new FlowLayout( ));
p2.add(b1);
p2.add(b2);
Panel p3=new Panel();
p3.setLayout(new GridLayout(2,1));
p3.add(p1);
p3.add(p2);
add(p3);
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource( )==b1)
{
int n=Integer.parseInt(t1.getText( ));
double y;
y= Math.sqrt(n);
t2.setText(""+y);
}
else
{
t1.setText("");
t2.setText("");
}
}
catch(Exception e)
{
System.out.println("Error..."+e);
dispose( );
}
}
public static void main(String args[])
{
SqRoot s=new SqRoot( );
s.validate( );
}
}