Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从虚拟数字键盘中获取小数点?_Java_Swing_Jbutton_Decimal Point_Numpad - Fatal编程技术网

Java 如何从虚拟数字键盘中获取小数点?

Java 如何从虚拟数字键盘中获取小数点?,java,swing,jbutton,decimal-point,numpad,Java,Swing,Jbutton,Decimal Point,Numpad,我试图通过点击GUI按钮来显示小数点。我使用下面的方法,它对数字有效,但对小数点无效。任何建议都很好。谢谢 private void displayWeightedquantity(ActionEvent event){ JButton currentButton = null; JButton[] numberButtonsarray = {bnDecimal,bnZero,bnOne, bnTwo, bnThree, bnFour, bnFive,bnSix,bnSeven,

我试图通过点击GUI按钮来显示小数点。我使用下面的方法,它对数字有效,但对小数点无效。任何建议都很好。谢谢

private void displayWeightedquantity(ActionEvent event){
    JButton currentButton = null;
    JButton[] numberButtonsarray = {bnDecimal,bnZero,bnOne, bnTwo, bnThree, bnFour, bnFive,bnSix,bnSeven,
                                    bnEight,bnNine};
        
    currentButton = (JButton)event.getSource();  
    for (int i = 0; i <numberButtonsarray.length; i++){
         if (currentButton == numberButtonsarray[i]){
             lbDisplayitemQty.setText(lbDisplayitemQty.getText() + currentButton.getText());  
             break;
             }
        } 
   }
private void displayWeightedquantity(ActionEvent事件){
JButton currentButton=null;
JButton[]numberButtonsarray={bnDecimal,bnZero,bnOne,bnTwo,bntree,bnFour,bnFive,bnSix,bnSeven,
八,九};
currentButton=(JButton)event.getSource();

对于(inti=0;i我怀疑问题出在代码的其他地方

我设置的测试很有效

您需要提供一个功能示例来说明问题,而不仅仅是一个代码片段


另外,确保decimal按钮已连接其动作侦听器

为了更快地获得更好的帮助,发布一个.BTW-我怀疑
ActionEvent.getActionCommand()
将生成大多数代码设计用于确定的字符。为什么要在按钮上循环?相反,如果(currentButton!=bnPurcahse | | currentButton!=bClear)lbDisplayitemQty.setText(lbDisplayitemQty.getText()+currentButton.getText())这是实现相同功能的一种更有效的方法。不管怎样,你的代码对我来说很好,所以我假设你在
bn decimal
中有一些打字错误,导致
currentButton==numberButtonsarray[I]
永远不会满足
的要求。我看不到该逻辑中有任何错误,所以我会去别处看看(或者接受上面的建议:)。我怀疑问题出在代码中的其他地方。我设置的测试可以找到。您需要提供一个功能示例来说明问题,而不仅仅是一个代码片段。确保decimal按钮具有其操作侦听器attached@evanmcdonnal我同意在评论中阅读代码。这太可怕了。哦,我们需要坚持原则如果这意味着OP以一种难以阅读的形式返回代码,他们只需要处理它。