You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

package Calculatorver1;
import javax.swing.*;
import java.awt.*;
public class CalculatorJFrame extends JFrame{
public CalculatorJFrame() {
initJFrame();
loadInterFace();
this.setVisible(true);
}
private void loadInterFace() {
JLabel j1 = new JLabel("简易计算器");
JLabel j2 = new JLabel("运算数一");
JLabel j3 = new JLabel("运算数二");
JLabel j4 = new JLabel("运算结果");
JLabel l1 = new JLabel(" ".repeat(1000));
JLabel l2 = new JLabel(" ".repeat(1000));
JLabel l3 = new JLabel(" ".repeat(1000));
JLabel l4 = new JLabel(" ".repeat(1000));
JLabel l5 = new JLabel(" ".repeat(1000));
JTextField t1 = new JTextField(10);
JTextField t2 = new JTextField(10);
JTextField t3 = new JTextField(10);
JButton b1 = new JButton("相加");
JButton b2 = new JButton("相减");
JButton b3 = new JButton("全部清零");
this.getContentPane().add(j1);
this.getContentPane().add(l1);
this.getContentPane().add(j2);
this.getContentPane().add(t1);
this.getContentPane().add(l2);
this.getContentPane().add(j3);
this.getContentPane().add(t2);
this.getContentPane().add(l3);
this.getContentPane().add(j4);
this.getContentPane().add(t3);
this.getContentPane().add(l4);
this.getContentPane().add(b1);
this.getContentPane().add(b2);
this.getContentPane().add(l5);
this.getContentPane().add(b3);
}
private void initJFrame() {
this.setSize(400,400);
this.setTitle("简易计算器");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(3);
this.setLayout(new FlowLayout());
}
}