2020-03-26
import javax.swing.*;
import java.awt.*;
public class Calculator extends JFrame {
public static void main(String[] args) {
new Calculator();
}
public Calculator() throws HeadlessException {
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4,4));
String[] strings = {"1", "2", "3", "+", "4", "5", "6", "-", "7", "8", "9", "*", "0", ".", "/", "="};
for (String text : strings) {
JButton button = new JButton(text);
panel.add(button);
}
this.getContentPane().add(new TextField(), BorderLayout.NORTH);
this.getContentPane().add(panel, BorderLayout.CENTER);
this.setBounds(0,0,300,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
广告 您可能关注的内容 |