展开全部
加点分,我帮你62616964757a686964616fe58685e5aeb931333365656466
算了,我给你写吧
放Ubuntu past了,有效期是1年:import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
public class Square {
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Square window = new Square();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Square() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 235, 315);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
JLabel label = new JLabel("长:");
label.setBounds(27, 31, 27, 41);
frame.getContentPane().add(label);
textField = new JTextField();
textField.setBounds(88, 39, 86, 24);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label_1 = new JLabel("宽:");
label_1.setBounds(27, 85, 27, 41);
frame.getContentPane().add(label_1);
textField_1 = new JTextField();
textField_1.setBounds(88, 93, 86, 24);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JLabel label_2 = new JLabel("面积:");
label_2.setBounds(27, 154, 43, 18);
frame.getContentPane().add(label_2);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(88, 151, 86, 24);
frame.getContentPane().add(textField_2);
JButton button = new JButton("计算");
button.setBounds(46, 213, 113, 27);
frame.getContentPane().add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Double d1 = Double.valueOf(textField.getText());
Double d2 = Double.valueOf(textField_1.getText());
Double d3 = (int) (d1 * d2 * 1000 + 0.5) / 1000.0;
textField_2.setText(d3.toString());
} catch (Exception e2) {
// TODO: handle exception
textField_2.setText("请输入数字!");
}
}
});
}
}