展开全部
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Main {
private static JTextField a = new JTextField(4);
private static JTextField b = new JTextField(4);
private static JTextField c = new JTextField(4);
public static void main(String[] args) {
e68a84e8a2ad3231313335323631343130323136353331333431376666JFrame frame = new JFrame("加法计算");
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
frame.add(a);
frame.add(new JLabel("+"));
frame.add(b);
JButton button = new JButton("=");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
c.setText(String.valueOf(Double.parseDouble(a.getText()) + Double.parseDouble(b.getText())));
}
});
frame.add(button);
frame.add(c);
frame.pack();
frame.setVisible(true);
}
}