该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Logic extends JFrame{
JFrame frame = new JFrame("计算器");
JPanel panel = new JPanel();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JTextField field1 = new JTextField(5);
JTextField field2 = new JTextField(5);
JButton button1 = new JButton("+");
JButton button2 = new JButton("-");
JButton button3 = new JButton("*");
JButton button4 = new JButton("/");
JButton button5 = new JButton("清空");
JLabel label=new JLabel("结果:");
JTextField field3 = new JTextField(5);
public Logic(){
panel1.add(field1);
panel1.add(field2);
panel.add(panel1);
panel2.add(button1);
panel2.add(button2);
panel2.add(button3);
panel2.add(button4);
panel.add(panel2);
panel3.add(label);
panel3.add(field3);
panel.add(panel3);
panel4.add(button5);
panel.add(panel4);
frame.add(panel);
frame.setBounds(500, 200, 280, 220);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
Double x = Double.parseDouble(field1.getText())+Double.parseDouble(field2.getText());
field3.setText(Double.toString(x));