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

