import java.awt.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JButton_test extends JFrame implements ActionListener {
     JButton jButton1 = new JButton(" 计 算 ");
     JTextField jText_number1 = new JTextField();
     JLabel jLabel1 = new JLabel("请输入一个数字");
     JLabel jLabel2 = new JLabel("结果:");
     JLabel jLabel3 = new JLabel("");
     public JButton_test() {
        setLayout(null);
        jButton1.setBounds(100, 105, 103, 25);
        jButton1.addActionListener(this);
        jLabel2.setBounds(44, 56, 50, 22);
        jLabel1.setBounds(15, 19, 99, 26);
        jLabel3.setBounds(120,56,100,22);
        jText_number1.setBounds(123, 14, 103, 32);
        setTitle("计算平方根");
        add(jLabel1);
        add(jText_number1);
        add(jLabel2);
        add(jLabel3);
        add(jButton1);
     }
     public void actionPerformed(ActionEvent e) {
         double number = 0;
         try {
              number = Double.valueOf(jText_number1.getText()).doubleValue();
              jLabel3.setText("" + Math.sqrt(number));
         }
         catch (NumberFormatException event) {
         } 
     }
     public static void main(String args[]) {
         JButton_test ta = new JButton_test();
         ta.setBounds(200, 200, 250, 200);
         ta.validate();
         ta.setVisible(true);
     }
}
