1. 简单计算器
纯手写
package com.jisuanqi;
import com.sun.xml.internal.ws.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
/**
* @date 2020/12/7 - 9:33
*/
public class MyCalculator {
private JFrame myCalculator;//计算器主页面
private JTextField display;//文本框
private JTextField result;//得到结果
private JPanel jPanel1;
private String nowButton;//输入的按钮
private JPanel jP_button;//按钮布局
private String str="";//输入的内容
private JFrame expansion;
private String x;//切换按钮
private String y;//返回按钮
private JPanel jPanel2;
private JPanel jGroup1;
private JPanel jGroup2;
private JPanel jGroup3;
private JPanel jGroup4;
private JPanel jGroup5;
private JPanel jGroup6;
private JPanel jGroup7;
private JPanel jGroup8;//按钮
private String rb;//单选按钮
private JRadioButton rButton1;
//private String rb2;//单选按钮
private JRadioButton rButton2;
ButtonGroup group ;
private JLabel jLabel1;//还款方式
private JLabel jLabel2;//贷款年限
private JLabel jLabel3;//贷款金额
private JLabel jLabel4;//贷款年利率
private JLabel jLabel5;//月均还款
private JLabel jLabel6;//利息总额
private JLabel jLabel7;//还款总额
private JTextField jTextField2;
private JTextField jTextField3;
private JTextField jTextField4;
private JTextField jTextField5;
private JTextField jTextField6;
private JTextField jTextField7;
private String jb1;//计算
private String jb2;//重新计算
private DecimalFormat df = new DecimalFormat("0.000");
public MyCalculator(){
myCalculator=new JFrame("简易计算器");
myCalculator.setVisible(true);
myCalculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
result = new JTextField(50);
result.setBackground(Color.PINK);
result.setFont(new Font("楷体",Font.BOLD,30));
result.setEnabled(true);
display=new JTextField(50);
display.setBackground(Color.LIGHT_GRAY);
display.setFont(new Font("楷体",Font.BOLD,20));
display.setEnabled(true);
jPanel1= new JPanel(new BorderLayout(0,0));
jPanel1.add(display,BorderLayout.CENTER);
jPanel1.add(result,BorderLayout.SOUTH);
myCalculator.add(jPanel1,BorderLayout.NORTH);
jP_button=new JPanel();
jP_button.setLayout(new GridLayout(5,4));
ActionListener command = new CommandListener();
ActionListener command1 = new expansionListener();
addButton("1",command);
addButton("2",command);
addButton("3",command);
addButton("+",command);
addButton("4",command);
addButton("5",command);
addButton("6",command);
addButton("-",command);
addButton("7",command);
addButton("8",command);
addButton("9",command);
addButton("*",command);
addButton(".",command);
addButton("0",command);
addButton("sqrt",command);
addButton("/",command);
addButton("=",command);
addButton("back",command);
addButton("AC",command);
addButton1("高级",command1);
myCalculator.add(jP_button,BorderLayout.CENTER);
myCalculator.setBounds(300,300,500,500);
/*====================================================================*/
expansion = new JFrame("贷款计算器");
expansion.setVisible(false);
expansion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ActionListener command2 = new backListener();
jPanel2=new J