发布网友 发布时间:2022-05-14 07:47
共1个回答
热心网友 时间:2022-04-23 15:58
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) {
JFrame 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);
}
}
追问能稍微简单一点,还有附Java程序MyEclipse截图吗?追答