资源简介
实现简单的加减乘除,没有实现小数点的运算,界面是使用WindowBuilder控件布局。
代码片段和文件信息
package com.homework.lhh;
import java.awt.EventQueue;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.JLabel;
@SuppressWarnings(“serial“)
public class Ex03 extends Jframe {
private static String strOne = ““;// 存数字
private static String strTwo = ““;// 存数字
private static double result;// 结果
private String operator = ““;// 运算符号
private static double numOne;
private static double numTwo;
private JPanel contentPane;
private JTextField textLED;
private JButton btn0;
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;
private JButton btn5;
private JButton btn6;
private JButton btn7;
private JButton btn8;
private JButton btn9;
private JButton btnReset;// 清零
private JButton btnWait;// 等号
private JButton btnAdd;// 加号
private JButton btnMinus;// 减号
private JButton btnRide;// 乘号
private JButton btnDivide;// 除号
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ex03 frame = new Ex03();
int w = (Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2;
int h = (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2;
frame.setLocation(w h);
frame.setVisible(true);
frame.setResizable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Ex03() {
settitle(“\u7B80\u5355\u5B9E\u73B0\u7684\u8BA1\u7B97\u5668“);
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setBounds(0 -57 472 546);
contentPane = new JPanel();
contentPane.setBackground(new Color(119 136 153));
contentPane.setBorder(new EmptyBorder(5 5 5 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textLED = new JTextField();
textLED.setFont(new Font(“宋体“ Font.PLAIN 18));
textLED.setBounds(14 13 428 55);
contentPane.add(textLED);
textLED.setColumns(10);
textLED.setHorizontalAlignment(JTextField.RIGHT);// 数字向右排列
btn1 = new JButton(“1“);
btn1.setBounds(14 288 97 78);
contentPane.add(btn1);
btn2 = new JButton(“2“);
btn2.setBounds(125 288 97 78);
contentPane.add(btn2);
btn3 = new JButton(“3“);
btn3.setBounds(236 288 97 78);
contentPane.add(btn3);
btn4 = new JButton(“4“);
btn4.setBounds(14 197 97 78);
contentPane.add(btn4);
btn5 = new JButton(“5“);
btn5.setBounds(125 197 97 78);
contentPane.add(btn5);
btn6 = new JButton(“6“);
btn6.setBounds(236 197 97 78);
contentPane.add(btn6);
btn7 = new JButton(“7“);
btn7.setBounds(14 106 97 78);
contentPane.add(btn7);
btn8 = new JButton(“8“);
btn8.setBounds(12
评论
共有 条评论