简体   繁体   English

这里的语法是什么?

[英]What's the syntax here?

Im writing calculator in java Swing and having issue with syntax: 我在用Java Swing编写计算器并且语法有问题:

https://imgur.com/gYtQuTC cannot resolve symbol dotButtonText is fixible with initializing before dotButton method,but it still asking for ")" ";" https://imgur.com/gYtQuTC无法解析符号dotButtonText通过dotButton方法之前的初始化是可修复的,但是它仍要求输入“)”“;”

  dotButton.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
    if(TextFieldDisplay.getText().equals("")){
      TextFieldDisplay.setText("0");
    }
    else if (TextFieldDisplay.getText().contains(".")){
      dotButton.setEnabled(false);
    }
    else
      (
              (String dotButtonText = TextFieldDisplay.getText()+dotButton.getText();
    TextFieldDisplay.setText(dotButtonText);

  }
});

I want to variable dotButtonText to take default value of "" if not pressed,and ".0" if button is pressed 我想让dotButtonText变量的默认值是“”(如果未按下),而“ .0”则是在按下按钮时

  1. You used ( instead of a curly braces { for your else block. 您使用了(而不是花括号{来代替else块。
  2. You have an extra ( at the beggining of your statement. 在声明的开头,您有一个额外的(

Remove those, and it will work fine: 删除那些,它将正常工作:

else
{
    String dotButtonText = TextFieldDisplay.getText()+dotButton.getText();
    TextFieldDisplay.setText(dotButtonText);
}
else {
   //";"expected  ")"expected  ")"expected after string
   // (String dotButtonText = TextFieldDisplay.getText()+dotButton.getText();
   TextFieldDisplay.setText(dotButtonText);
}

You have added an extra ( . Remove it and everything will work fine. 您添加了一个额外的( 。删除它,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM