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

问题描述

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

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

解决方案

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

    }

}

}

解决方案二:

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

时间: 2024-12-31 18:03:59

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

微信-我用java做了几个小功能,想放到公众号上可以访问,现在不知道怎么办了,请帮助,能留下QQ最好

问题描述 我用java做了几个小功能,想放到公众号上可以访问,现在不知道怎么办了,请帮助,能留下QQ最好 用jsp做的几个小功能,想要在微信订阅号上可以访问,求帮助,能留下QQ最好,谢谢了 解决方案 申请公众号 我同学是用jfinal开发的

另外我想问Java 环境下 怎么做域名映射到 Java环境的工程 ?配置网站映射IP和域名问题

各位大神:请问 服务上配置本地程序能访问网站,但是用tomcat发布网站却不行,不知道怎么讲域名和IP地址进行映射(IP地址已经解析过),以前用IIS发布可以,现在不想用IIS(我用的是java语言),想直接用apache和tomcat配置发布网站可以吗?但是tomcat配置好了,域名和IP都指定了,但是还是不行,请查看什么问题,谢谢. 另外我想问Java 环境下 怎么做域名映射到 Java环境的工程 ?

java datatable中怎么做排序编号!

问题描述 java datatable中怎么做排序编号! 我现在需要在excel行号前面加一列编号,并且按顺序来排列!例如1.2.3.4..... 解决方案 你用的是什么数据库?现在几个主流的数据库都有ROWNUM 或者参考How to display dataTable row numbers in JSF这篇文章和源码是否对你有帮助.

c#-C#不如JAVA吗?为什么做ios MDM 的时候推送这么小的问题无法解决

问题描述 C#不如JAVA吗?为什么做ios MDM 的时候推送这么小的问题无法解决 http://stackoverflow.com/search?q=C%23+MDM 好多人都在问,推送后,代码没有任何报错,没有任何异常,设备就是没反应,碰到这种情况该往哪方向突破,系统日志什么的看了根本没有异常,当然推送证书有可能有问题,是按照网上提供的方式制作的这个不能保证,其他的完全是按照标准来完成的,checkin也可以,就差推送了,折腾1周了,各种资料都翻了,全是JAVA的,非要转JAVA做吗? 解

新人一枚,关于Java dynamic Web Project做的项目的页面跳转点击问题

问题描述 新人一枚,关于Java dynamic Web Project做的项目的页面跳转点击问题 最近学的java做了一个基于Java语言的DWP的项目,页面的跳转没问题,可以正常跳转,但是在重复几次的点击后,整个页面就无法点击跳转了,点了没有任何效果.各位大神,如何解决?新人求教! 解决方案 麻烦说的详细一点,框架用的是什么,还是直接用servlet来接收的请求,进行了什么操作之后点击无法跳转.会不会是因为页面上的链接或者form表单中就没有跳转地址. 解决方案二: 看看地址有没有写错啊

JAVA之旅(四)——面向对象思想,成员/局部变量,匿名对象,封装 , private,构造方法,构造代码块

JAVA之旅(四)--面向对象思想,成员/局部变量,匿名对象,封装 , private,构造方法,构造代码块 加油吧,节奏得快点了 1.概述 上篇幅也是讲了这点,这篇幅就着重的讲一下思想和案例 就拿买电脑来说吧,首先,你不懂电脑,你去电脑城买电脑,和大象装冰箱里一样,是什么步骤?咨询 砍价 ,谈妥了就那电脑走人,对吧,这就是面向过程的思想,而面向对象是:你有一个哥们,他懂电脑,什么都会,你只要带他去,就行,你这个哥们就是对象,在JAVA中,我们就是操作一个对象去完成各种各样的操作的,这就是面向对

JAVA之旅(十六)——String类,String常用方法,获取,判断,转换,替换,切割,子串,大小写转换,去除空格,比较

JAVA之旅(十六)--String类,String常用方法,获取,判断,转换,替换,切割,子串,大小写转换,去除空格,比较 过节耽误了几天,我们继续JAVA之旅 一.String概述 String时我们很常用的数据类型,他也是一个类的使用 我们来看 package com.lgl.hellojava; //公共的 类 类名 public class HelloJJAVA { public static void main(String[] args) { /** * String */ /**

利用QQ漂流瓶做外链考虑清楚再执行 请勿盲目跟风

近来网上流传"巧用QQ漂流瓶做外链"的方法,这种方法对于做外链来说确实是一种很新鲜的外链方式,我本人就此而尝试过多次,经仔细分析结果效果不大.或许是我没有利用好QQ漂流瓶,也或许是QQ漂流瓶做外链推广的价值本身就不大.不过针对QQ漂流瓶做外链,我确实存在了一些真实的感受,因此,我想和大家交流交流我的心得,经过分析再三,我个人倒是认为利用QQ漂流瓶做外链需要考虑清楚后再执行,请勿盲目跟风. QQ漂流瓶做外链的优点我简单的抽取两个重要点概括入下: 1.QQ漂流瓶已经分好类,比如传递瓶.同城

c++-有谁看过《由浅入深学C++—基础、进阶与必做300题》,有问题想请教

问题描述 有谁看过<由浅入深学C++-基础.进阶与必做300题>,有问题想请教 1C 这是系统中的一部分,想要添加人员信息.本书的最后一章<人事管理系统开发实例>有问题请教.里面的Link是个什么东西?代码很长,无法全部粘贴,还望看过此书的人给予帮助. 解决方案 http://baike.baidu.com/link?url=b2nUFFYcHlAdXbDP0i1p87HOUNWR4KHZKpZIOuH3F3ilFc3MI-6DwaL1ThAD8EcXi9zgQoHtWPvPuCy