|
import java.awt. *;
import Java.awt.event. *;
import java.swing. *;
public class AppGraphInOut
{
public static void main (String args [])
{
new AppFrame ();
}
}
The
class AppFrame extends JFrame
{
JTextField in = new JTextField (10);
JButton btn = new JButton ("Squaring");
JLabel out = new JLabel ("Label for displaying results");
The
public AppFrame ()
{
setLayout (new FlowLayout ());
getContentPane (). add (in);
getContentPane (). add (btn);
getContentpane (). add (out);
btn.addActionListener (new BtnActionAdapter ());
setSize (400,100);
setDefaultCloseOperatorion (DISPOSE_ON_CLOSE);
setVisible (ture);
}
The
class BtnActionAdapter implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
String s = in.getText ();
double d = Double.parseDouble (s);
double sq = d * d;
The square of out.setText (d + "is:" + sq);
}
}
} |
|