用JAVA已经按照window7做了标准型的计算器,再就想实现标准型和科学型的转换,请问如何加代码

用JAVA已经编写了一个标准型的计算器,按照window7做的标准型的计算器,再就是想想计算器一样可以切换标准型和科学型的转换,就不会了,想实现标准型和科学型的转换,代码也已经有了,请问如何加代码,谢谢,求帮忙谢谢了
图片说明

2个回答

package calculator;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;

/**

  • MC:清除独立内存里的数字 MR:读出独立内存数字
  • MS:将显示数字保存到独立内存,并取代内存中原有数字
  • M+:把目前显示的值放在存储器中;中断数字输入.
  • M-:从存储器内容中减去当前显示值;中断数字输入. (独立内存是一个临时寄放数字的存储器,方便计算)
  • CE:纠错键(CLEARERROR)。输入数字有错,按它可以重新输入
  • C:表示清零,将计算器恢复到开机状态 */

public class CalculatorDemo extends JFrame {
// 声明组件
private JMenuBar bar;// 菜单栏
private JMenu menuView;// 查看菜单项
private JRadioButtonMenuItem science;// 科学型
private JRadioButtonMenuItem standard;// 标准型
private JMenu menuEdit;// 编辑菜单项
private JMenuItem ctrlc;// 复制
private JMenuItem ctrlv;// 粘贴
private JMenu menuHelp;// 帮助菜单项
private JMenuItem viewHelp;// 查看帮助
private JMenuItem aboutCalculator;// 关于计算器

private JPanel panel;
private JTextField text;
private JPanel panelBtn;

private JLabel btnMC, btnMR, btnMS, btnMAdd, btnMReduce, btnBack, btnCE,
        btnC, btnAR, btnSqrt, btn0, btnPoint, btn1, btn2, btn3, btn4, btn5,
        btn6, btn7, btn8, btn9, btnAdd, btnReduce, btnMultiply, btnDivide,
        btnMod, btnBottom, btnEqual;

/** 保存预执行操作的数 */
private double value = 0;
/** 是否已经保存 */
private boolean hasSaved = false;
/** 保存的数字 */
private double saveNum = 0;
/** 运算操作:0:无操作。1:加。2:减。3:乘。4:除。 */
private int operation = 0;
/** 保存临时数据 */
private StringBuffer tmp = new StringBuffer();
/** 文字框允许输入的数字长度 */
private int allowLength = 32;

private boolean hasPressed = false;

public CalculatorDemo() {

}

public void init() {

    // 创建组件
    bar = new JMenuBar();
    bar.setBackground(new Color(217, 223, 240));
    menuView = new JMenu("查看(V)");
    standard = new JRadioButtonMenuItem("标准型(T)");
    standard.setSelected(true);
    science = new JRadioButtonMenuItem("科学型(S)");
    ButtonGroup group = new ButtonGroup();
    group.add(standard);
    group.add(science);

    menuEdit = new JMenu("编辑(E)");
    ctrlc = new JMenuItem("复制(C)");
    ctrlv = new JMenuItem("粘贴(P)");

    menuHelp = new JMenu("帮助(H)");
    viewHelp = new JMenuItem("查看帮助(V)");
    aboutCalculator = new JMenuItem("关于计算器(A)");

    panel = new JPanel(new BorderLayout(10, 3));
    // panel.setBackground(Color.red);

    text = new JTextField("0");
    text.setEditable(false);
    text.setBackground(Color.WHITE);
    // Insets(int top, int left, int bottom, int right)
    // 创建并初始化具有指定顶部、左边、底部、右边 inset 的新 Insets 对象。
    text.setMargin(new Insets(0, 6, 0, 8));
    text.setHorizontalAlignment(JTextField.RIGHT);

    panelBtn = new JPanel();
    panelBtn.setBackground(new Color(217, 223, 240));
    panelBtn.setLayout(null);

    btnMC = new JLabel(new ImageIcon("image/mc1.png"));
    btnMC.setBounds(10, 5, 34, 27);
    btnMR = new JLabel(new ImageIcon("image/mr1.png"));
    btnMR.setBounds(50, 5, 34, 27);
    btnMS = new JLabel(new ImageIcon("image/ms1.png"));
    btnMS.setBounds(90, 5, 34, 27);
    btnMAdd = new JLabel(new ImageIcon("image/m+1.png"));
    btnMAdd.setBounds(130, 5, 34, 27);
    btnMReduce = new JLabel(new ImageIcon("image/m-1.png"));
    btnMReduce.setBounds(170, 5, 34, 27);
    btnBack = new JLabel(new ImageIcon("image/b1.png"));
    btnBack.setBounds(10, 40, 34, 27);
    btnCE = new JLabel(new ImageIcon("image/ce1.png"));
    btnCE.setBounds(50, 40, 34, 27);
    btnC = new JLabel(new ImageIcon("image/c1.png"));
    btnC.setBounds(90, 40, 34, 27);
    btnAR = new JLabel(new ImageIcon("image/ar1.png"));
    btnAR.setBounds(130, 40, 34, 27);
    btnSqrt = new JLabel(new ImageIcon("image/s1.png"));
    btnSqrt.setBounds(170, 40, 34, 27);
    btn7 = new JLabel(new ImageIcon("image/71.png"));
    btn7.setBounds(10, 75, 34, 27);
    btn8 = new JLabel(new ImageIcon("image/81.png"));
    btn8.setBounds(50, 75, 34, 27);
    btn9 = new JLabel(new ImageIcon("image/91.png"));
    btn9.setBounds(90, 75, 34, 27);
    btnDivide = new JLabel(new ImageIcon("image/d1.png"));
    btnDivide.setBounds(130, 75, 34, 27);
    btnMod = new JLabel(new ImageIcon("image/mod1.png"));
    btnMod.setBounds(170, 75, 34, 27);
    btn4 = new JLabel(new ImageIcon("image/41.png"));
    btn4.setBounds(10, 110, 34, 27);
    btn5 = new JLabel(new ImageIcon("image/51.png"));
    btn5.setBounds(50, 110, 34, 27);
    btn6 = new JLabel(new ImageIcon("image/61.png"));
    btn6.setBounds(90, 110, 34, 27);
    btnMultiply = new JLabel(new ImageIcon("image/m1.png"));
    btnMultiply.setBounds(130, 110, 34, 27);
    btnBottom = new JLabel(new ImageIcon("image/bt1.png"));
    btnBottom.setBounds(170, 110, 34, 27);
    btn1 = new JLabel(new ImageIcon("image/11.png"));
    btn1.setBounds(10, 145, 34, 27);
    btn2 = new JLabel(new ImageIcon("image/21.png"));
    btn2.setBounds(50, 145, 34, 27);
    btn3 = new JLabel(new ImageIcon("image/31.png"));
    btn3.setBounds(90, 145, 34, 27);
    btnReduce = new JLabel(new ImageIcon("image/r1.png"));
    btnReduce.setBounds(130, 145, 34, 27);
    btnEqual = new JLabel(new ImageIcon("image/e1.png"));
    btnEqual.setBounds(170, 145, 34, 62);
    btn0 = new JLabel(new ImageIcon("image/01.png"));
    btn0.setBounds(10, 180, 73, 27);
    btnPoint = new JLabel(new ImageIcon("image/p1.png"));
    btnPoint.setBounds(90, 180, 34, 27);
    btnAdd = new JLabel(new ImageIcon("image/a1.png"));
    btnAdd.setBounds(130, 180, 34, 27);

    // 布局
    menuView.add(standard);
    menuView.add(science);
    menuEdit.add(ctrlc);
    menuEdit.add(ctrlv);
    menuHelp.add(viewHelp);
    menuHelp.add(aboutCalculator);
    bar.add(menuView);
    bar.add(menuEdit);
    bar.add(menuHelp);

    panelBtn.add(btnMC);
    panelBtn.add(btnMR);
    panelBtn.add(btnMS);
    panelBtn.add(btnMAdd);
    panelBtn.add(btnMReduce);
    panelBtn.add(btnBack);
    panelBtn.add(btnCE);
    panelBtn.add(btnC);
    panelBtn.add(btnAR);
    panelBtn.add(btnSqrt);
    panelBtn.add(btn7);
    panelBtn.add(btn8);
    panelBtn.add(btn9);
    panelBtn.add(btnDivide);
    panelBtn.add(btnMod);
    panelBtn.add(btn4);
    panelBtn.add(btn5);
    panelBtn.add(btn6);
    panelBtn.add(btnMultiply);
    panelBtn.add(btnBottom);
    panelBtn.add(btn1);
    panelBtn.add(btn2);
    panelBtn.add(btn3);
    panelBtn.add(btnReduce);
    panelBtn.add(btnEqual);
    panelBtn.add(btn0);
    panelBtn.add(btnPoint);
    panelBtn.add(btnAdd);

    panel.add(text, BorderLayout.NORTH);
    panel.add(panelBtn);
    this.setJMenuBar(bar);
    this.add(panel);
    // 对frame进行设置
    this.setTitle("计算器");
    this.setBounds(555, 185, 220, 300);
    this.setVisible(true);
    this.setResizable(false);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // 窗体图标
    Image icon = Toolkit.getDefaultToolkit().getImage("image/10.png");
    this.setIconImage(icon);

    // 加监听
    MyListener myLis = new MyListener();
    btnMC.addMouseListener(myLis);
    btnMR.addMouseListener(myLis);
    btnMS.addMouseListener(myLis);
    btnMAdd.addMouseListener(myLis);
    btnMReduce.addMouseListener(myLis);
    btnBack.addMouseListener(myLis);
    btnCE.addMouseListener(myLis);
    btnC.addMouseListener(myLis);
    btnAR.addMouseListener(myLis);
    btnSqrt.addMouseListener(myLis);
    btn0.addMouseListener(myLis);
    btnPoint.addMouseListener(myLis);
    btn1.addMouseListener(myLis);
    btn2.addMouseListener(myLis);
    btn3.addMouseListener(myLis);
    btn4.addMouseListener(myLis);
    btn5.addMouseListener(myLis);
    btn6.addMouseListener(myLis);
    btn7.addMouseListener(myLis);
    btn8.addMouseListener(myLis);
    btn9.addMouseListener(myLis);
    btnAdd.addMouseListener(myLis);
    btnReduce.addMouseListener(myLis);
    btnMultiply.addMouseListener(myLis);
    btnDivide.addMouseListener(myLis);
    btnMod.addMouseListener(myLis);
    btnBottom.addMouseListener(myLis);
    btnEqual.addMouseListener(myLis);

    //复制监听
    ctrlc.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            text.selectAll();
            text.copy();
        }
    });

    //粘贴监听
    ctrlv.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
                if(t!=null && t.isDataFlavorSupported(DataFlavor.stringFlavor)){
                    //得到剪贴板中的字符串
                    String txt = t.getTransferData(DataFlavor.stringFlavor).toString();
                    //得到 字符串中的 数字和. 得到的是数组。
                    String[] sp = txt.split("[\\D&&[^.]]");
                    //从数组中得到最后一个数字
                    if(sp.length>0){
                        String str = sp[sp.length-1];
                        System.out.println(str);
                        //对得到的数字再次以.分割
                        String[] sp2 = str.split("\\.");
                        System.out.println(sp2.length);
                        //对于数组长度大于2的得到后两个数组成的小数
                        if(sp2.length>1){
                            String x = sp2[sp2.length-2];
                            txt =( x.equals("")?"0":x)+"."+sp2[sp2.length-1];
                        }
                        //对于数组长度等于1的直接可以使用
                        //else if(sp2.length==1)
                        //  text = sp2[sp2.length-1];
                        //对于数组长度等于0的
                        else
                            //text = sp[sp.length-1];
                            txt = sp2[sp2.length-1];
                        text.setText(txt);
                    }

                }
            } catch (HeadlessException e1) {
                System.out.println("错误:"+e1.getMessage());
            } catch (UnsupportedFlavorException e1) {
                System.out.println("错误:"+e1.getMessage());
            } catch (IOException e1) {
                System.out.println("错误:"+e1.getMessage());
            }
        }
    });

    //查看帮助监听
    aboutCalculator.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new About();
        }
    });
}

// 显示结果
private void showResult(String result) {
    text.setText(result.endsWith(".0") ? result.substring(0,
            result.length() - 2) : result);
    tmp = new StringBuffer();
}

/**
 * 计算结果并显示结果。
 * 
 * @param value2
 *            第二个操作数。
 */
private void countResult(double value2) {
    double result = 0;
    switch (operation) {
    case 1:
        result = value + value2;
        break;
    case 2:
        result = value - value2;
        break;
    case 3:
        result = value * value2;
        break;
    case 4:
        result = value / value2;
        break;
    }
    showResult(result + "");
    hasPressed = false;
    value = result;
}

// 清空结果。
private void clearAll(String result) {
    showResult(result);
    value = 0;
    operation = 0;
    hasPressed = false;
}

class MyListener implements MouseListener {

    @Override
    public void mouseClicked(MouseEvent e) {

        double value2;
        try {
            value2 = Double.parseDouble(text.getText());
        } catch (NumberFormatException e1) {
            System.out.println("错误:" + e1.getMessage());
            value2 = 0;
        }

        Object obj = e.getSource();
        if (obj instanceof JLabel) {
            JLabel lbl = (JLabel) obj;
            if (lbl == btnMC) {// MC:清除独立内存里的数字
                if (hasSaved) {
                    saveNum = 0;
                    hasSaved = false;
                }
            } else if (lbl == btnMR) { // MR:读出独立内存数字
                String result = saveNum + "";
                text.setText(result.endsWith(".0") ? result.substring(0,
                        result.length() - 2) : result);
            } else if (lbl == btnMS) { // MS:将显示数字保存到独立内存,并取代内存中原有数字
                if (value2 != 0) {
                    saveNum = value2;
                    hasSaved = true;
                }
            } else if (lbl == btnMAdd) {// M+:把目前显示的值放在存储器中;中断数字输入
                if (value2 != 0) {
                    saveNum += value2;
                    hasSaved = true;
                }
            } else if (lbl == btnMReduce) { // M-:从存储器内容中减去当前显示值;中断数字输入
                if (value2 != 0) {
                    saveNum -= value2;
                    hasSaved = true;
                }
            } else if (lbl == btnBack) {// <-- backspace
                if (tmp.length() == 1)
                    showResult("0");
                if (tmp.length() > 1) {
                    tmp.deleteCharAt(tmp.length() - 1);
                    text.setText(tmp.toString());
                }
            } else if (lbl == btnCE) {// CE:纠错键(CLEARERROR)。输入数字有错,按它可以重新输入 
                clearAll("0");
            } else if (lbl == btnC) {// C:表示清零,将计算器恢复到开机状态
                clearAll("0");
            } else if (lbl == btnAR) {// +/-
                if (value2 != 0)
                    showResult((value2 * -1) + "");
            } else if (lbl == btnSqrt) {// sqrt
                if (value2 != 0)
                    showResult(Math.sqrt(value2) + "");
            } else if (lbl == btn7) { // 7
                if (tmp.length() <= allowLength) {
                    tmp.append("7");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btn8) { // 8
                if (tmp.length() <= allowLength) {
                    tmp.append("8");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btn9) {// 9
                if (tmp.length() <= allowLength) {
                    tmp.append("9");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btnDivide) {// / 除
                if (operation != 0 && hasPressed) {
                    countResult(value2);
                }
                value = Double.parseDouble(text.getText());
                if (tmp.length() > 0) {
                    tmp = new StringBuffer();
                }
                operation = 4;
            } else if (lbl == btnMod) {// %
                showResult((value * value2 / 100) + "");
            } else if (lbl == btn4) {
                if (tmp.length() <= allowLength) {
                    tmp.append("4");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btn5) {// 5
                if (tmp.length() <= allowLength) {
                    tmp.append("5");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btn6) {// 6
                if (tmp.length() <= allowLength) {
                    tmp.append("6");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btnMultiply) { // *
                if (operation != 0 && hasPressed) {
                    countResult(value2);
                }
                value = Double.parseDouble(text.getText());
                if (tmp.length() > 0) {
                    tmp = new StringBuffer();
                }
                operation = 3;
            } else if (lbl == btnBottom) { // 1/x
                if (value2 != 0)
                    showResult((1 / value2) + "");
                else
                    showResult("");
            } else if (lbl == btn1) {
                if (tmp.length() <= allowLength) {
                    tmp.append("1");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btn2) { // 2
                if (tmp.length() <= allowLength) {
                    tmp.append("2");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btn3) {// 3
                if (tmp.length() <= allowLength) {
                    tmp.append("3");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btnReduce) {// -
                if (operation != 0 && hasPressed) {
                    countResult(value2);
                }
                value = Double.parseDouble(text.getText());
                if (tmp.length() > 0) {
                    tmp = new StringBuffer();
                }
                operation = 2;
            } else if (lbl == btnEqual) {// =
                if (operation != 0) {
                    double result = 0;
                    switch (operation) {
                    case 1:
                        result = value + value2;
                        break;
                    case 2:
                        result = value - value2;
                        break;
                    case 3:
                        result = value * value2;
                        break;
                    case 4:
                        result = value / value2;
                        break;
                    }
                    showResult(result + "");
                    hasPressed = false;
                }
            } else if (lbl == btn0) { // 0
                if (tmp.length() <= allowLength) {
                    tmp.append("0");
                    text.setText(tmp.toString());
                    if (operation != 0 && hasPressed == false)
                        hasPressed = true;
                }
            } else if (lbl == btnPoint) {// .
                // 判断是有已有小数点
                if (text.getText().indexOf(".") == -1) {
                    tmp.append(".");
                    text.setText(tmp.toString());
                }

            } else if (lbl == btnAdd) {// +
                if (operation != 0 && hasPressed) {
                    countResult(value2);
                }
                value = Double.parseDouble(text.getText());
                if (tmp.length() > 0) {
                    tmp = new StringBuffer();
                }
                operation = 1;
            } 
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        Object obj = e.getSource();
        if (obj instanceof JLabel) {
            JLabel lbl = (JLabel) obj;
            if (lbl == btnMC) {
                btnMC.setIcon(new ImageIcon("image/mc2.png"));
            } else if (lbl == btnMR) {
                btnMR.setIcon(new ImageIcon("image/mr2.png"));
            } else if (lbl == btnMS) {
                btnMS.setIcon(new ImageIcon("image/ms2.png"));
            } else if (lbl == btnMAdd) {
                btnMAdd.setIcon(new ImageIcon("image/m+2.png"));
            } else if (lbl == btnMReduce) {
                btnMReduce.setIcon(new ImageIcon("image/m-2.png"));
            } else if (lbl == btnBack) {
                btnBack.setIcon(new ImageIcon("image/b2.png"));
            } else if (lbl == btnCE) {
                btnCE.setIcon(new ImageIcon("image/ce2.png"));
            } else if (lbl == btnC) {
                btnC.setIcon(new ImageIcon("image/c2.png"));
            } else if (lbl == btnAR) {
                btnAR.setIcon(new ImageIcon("image/ar2.png"));
            } else if (lbl == btnSqrt) {
                btnSqrt.setIcon(new ImageIcon("image/s2.png"));
            } else if (lbl == btn7) {
                btn7.setIcon(new ImageIcon("image/72.png"));
            } else if (lbl == btn8) {
                btn8.setIcon(new ImageIcon("image/82.png"));
            } else if (lbl == btn9) {
                btn9.setIcon(new ImageIcon("image/92.png"));
            } else if (lbl == btnDivide) {
                btnDivide.setIcon(new ImageIcon("image/d2.png"));
            } else if (lbl == btnMod) {
                btnMod.setIcon(new ImageIcon("image/mod2.png"));
            } else if (lbl == btn4) {
                btn4.setIcon(new ImageIcon("image/42.png"));
            } else if (lbl == btn5) {
                btn5.setIcon(new ImageIcon("image/52.png"));
            } else if (lbl == btn6) {
                btn6.setIcon(new ImageIcon("image/62.png"));
            } else if (lbl == btnMultiply) {
                btnMultiply.setIcon(new ImageIcon("image/m2.png"));
            } else if (lbl == btnBottom) {
                btnBottom.setIcon(new ImageIcon("image/bt2.png"));
            } else if (lbl == btn1) {
                btn1.setIcon(new ImageIcon("image/12.png"));
            } else if (lbl == btn2) {
                btn2.setIcon(new ImageIcon("image/22.png"));
            } else if (lbl == btn3) {
                btn3.setIcon(new ImageIcon("image/32.png"));
            } else if (lbl == btnReduce) {
                btnReduce.setIcon(new ImageIcon("image/r2.png"));
            } else if (lbl == btnEqual) {
                btnEqual.setIcon(new ImageIcon("image/e2.png"));
            } else if (lbl == btn0) {
                btn0.setIcon(new ImageIcon("image/02.png"));
            } else if (lbl == btnPoint) {
                btnPoint.setIcon(new ImageIcon("image/p2.png"));
            } else if (lbl == btnAdd) {
                btnAdd.setIcon(new ImageIcon("image/a2.png"));
            }

        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        Object obj = e.getSource();
        if (obj instanceof JLabel) {
            JLabel lbl = (JLabel) obj;
            if (lbl == btnMC) {
                btnMC.setIcon(new ImageIcon("image/mc1.png"));
            } else if (lbl == btnMR) {
                btnMR.setIcon(new ImageIcon("image/mr1.png"));
            } else if (lbl == btnMS) {
                btnMS.setIcon(new ImageIcon("image/ms1.png"));
            } else if (lbl == btnMAdd) {
                btnMAdd.setIcon(new ImageIcon("image/m+1.png"));
            } else if (lbl == btnMReduce) {
                btnMReduce.setIcon(new ImageIcon("image/m-1.png"));
            } else if (lbl == btnBack) {
                btnBack.setIcon(new ImageIcon("image/b1.png"));
            } else if (lbl == btnCE) {
                btnCE.setIcon(new ImageIcon("image/ce1.png"));
            } else if (lbl == btnC) {
                btnC.setIcon(new ImageIcon("image/c1.png"));
            } else if (lbl == btnAR) {
                btnAR.setIcon(new ImageIcon("image/ar1.png"));
            } else if (lbl == btnSqrt) {
                btnSqrt.setIcon(new ImageIcon("image/s1.png"));
            } else if (lbl == btn7) {
                btn7.setIcon(new ImageIcon("image/71.png"));
            } else if (lbl == btn8) {
                btn8.setIcon(new ImageIcon("image/81.png"));
            } else if (lbl == btn9) {
                btn9.setIcon(new ImageIcon("image/91.png"));
            } else if (lbl == btnDivide) {
                btnDivide.setIcon(new ImageIcon("image/d1.png"));
            } else if (lbl == btnMod) {
                btnMod.setIcon(new ImageIcon("image/mod1.png"));
            } else if (lbl == btn4) {
                btn4.setIcon(new ImageIcon("image/41.png"));
            } else if (lbl == btn5) {
                btn5.setIcon(new ImageIcon("image/51.png"));
            } else if (lbl == btn6) {
                btn6.setIcon(new ImageIcon("image/61.png"));
            } else if (lbl == btnMultiply) {
                btnMultiply.setIcon(new ImageIcon("image/m1.png"));
            } else if (lbl == btnBottom) {
                btnBottom.setIcon(new ImageIcon("image/bt1.png"));
            } else if (lbl == btn1) {
                btn1.setIcon(new ImageIcon("image/11.png"));
            } else if (lbl == btn2) {
                btn2.setIcon(new ImageIcon("image/21.png"));
            } else if (lbl == btn3) {
                btn3.setIcon(new ImageIcon("image/31.png"));
            } else if (lbl == btnReduce) {
                btnReduce.setIcon(new ImageIcon("image/r1.png"));
            } else if (lbl == btnEqual) {
                btnEqual.setIcon(new ImageIcon("image/e1.png"));
            } else if (lbl == btn0) {
                btn0.setIcon(new ImageIcon("image/01.png"));
            } else if (lbl == btnPoint) {
                btnPoint.setIcon(new ImageIcon("image/p1.png"));
            } else if (lbl == btnAdd) {
                btnAdd.setIcon(new ImageIcon("image/a1.png"));
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

}

}

最简单的是将高级功能也放在窗体上,通过切换窗体的大小实现隐藏显示。

HLLLLLL_
HLLLLLL_ 有完整代码吗
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐