|
import java.awt.*;
import Java.awt.event.*;
import java.swing.*;
public class AppGraphInOut
{
public static void main( String args[])
{
new AppFrame();
}
}
class AppFrame extends JFrame
{
JTextField in = new JTextField(10);
JButton btn = new JButton("求平方");
JLabel out = new JLabel("用于显示结果的标签");
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);
}
class BtnActionAdapter implements ActionListener
{
public void actionPerformed ( ActionEvent e)
{
String s = in.getText();
double d = Double.parseDouble( s );
double sq = d * d;
out.setText(d +"的平方是:"+sq);
}
}
}
|
|