0

我需要一些帮助来获取整数,然后在我从用户添加的内容中获取整数后,我需要向它添加 10,感谢帮助,代码如下;\

private void btnCalculateMouseClicked(java.awt.event.MouseEvent evt) 
{                                          
    Integer memoryAdd1, total, radBlue1, radWhite1, radBlack1, microsoftYes1, 
        caseA1, batteryA1, webcamA1, windows20001, windowsVista1;

    radBlack1 = 0;
    radWhite1 = 0;
    radBlue1 = 0;
    microsoftYes1 = 0;
    caseA1 = 0;
    batteryA1 = 0;
    webcamA1 = 0;
    windows20001 = 0;
    windowsVista1 = 0;
    memoryAdd1 = 0;

    if (radBlack.isSelected()) { radBlack1 = radBlack1 + 5; };

    if (radWhite.isSelected()) { radWhite1 = radWhite1 + 5; };

    if (radBlue.isSelected()) { radWhite1 = radWhite1 + 10; };

    memoryAdd.getText(Integer.toString( memoryAdd1 = memoryAdd1+10));

    if (microsoftYes.isSelected()) { microsoftYes1 = microsoftYes1 + 100; };

    if (caseA.isSelected()) { caseA1 = caseA1 + 50; };

    if (batteryA.isSelected()) { batteryA1 = batteryA1 + 30; };

    if (webcamA.isSelected()) { webcamA1 = webcamA1 + 25; };

    if (windows2000.isSelected()) { windows20001 = windows20001 + 300; };

    if (windowsVista.isSelected()) { windowsVista1 = windowsVista1 + 300; };

    total = radBlack1 + radWhite1 + radBlue1 + microsoftYes1 + caseA1 + 
        batteryA1 + webcamA1 + windows20001 + windowsVista1;

    beforeTax.setText(Integer.toString(total));

}

4

2 回答 2

2

看起来只是铸造问题..



    MemoryAdd1+=10 
    String str = Integer.toString( memoryAdd1)
    memoryAdd.getText(str);

顺便问一下你的记忆力是什么?它是 AWT 文本框吗?您是否要在其中设置值?

于 2012-12-09T02:50:55.860 回答
1

您的问题是,一旦值在转换函数中,您就不能再用它进行数学运算了,因为它现在是一个字符串。

试试这个

MemoryAdd1+=10

memoryAdd.getText(Integer.toString( memoryAdd1));
于 2012-12-09T01:48:39.567 回答