title: Javafx Break or stop button event handler
body: <p>I am still a beginner in Java and JavaFX and I am struggling at the moment on how to make a way to stop/break an event that is happening when a button is clicked.
  So, I am building a program that adds Products(class) into a TableView. So far, everything is working fine, the Products are added successfully and their parameters are checked by my custom functions, whether the user had entered string/double/integer values respectively in the Name/Price/Amount fields.</p>
  
  <p>In my check function, there is also an error printed when the entered value is incorrect BUT I want to also make it so that when an incorrect value is enter, all of the entered data in the 3 fields is nullified/erased. For that reason, somehow the event handler of the "Add" button needs to stop/break. I want to do this, because even if an error in the console appears, that either the Name/Price/Amount are falsely input, the other values that are entered correctly, will still print in the table. Thus resulting in data, for example, like:
  Name: Fish
  Price: 
  Amount: 3
  ^In the case that the Price value was not a correct double number but some string or other. I have a delete button that can remove any data from the table, thus the wrongly entered one, but I want "to save time" for that or just make the program "smarter".
  I also forgot to mention, that my checkString/Double/Int function use try/catch block, so I have made it so, that when there is an error, a message will be printed and some "default" value will be returned (since the function requires a return value). But let me just show you the code:</p>
  
  <p>Product class:</p>
  
  <pre><code>public class Product{
  private SimpleStringProperty name;
  private SimpleDoubleProperty price;
  private SimpleIntegerProperty amount;
  //private SimpleIntegerProperty ID=0;
  
  public Product(){
      this.name =new SimpleStringProperty("");
      this.price = new SimpleDoubleProperty(0);
      this.amount = new SimpleIntegerProperty(0);
      //this.ID=0;
  }
  public Product(String name, double price, int amount /* int id */){
      this.name =new SimpleStringProperty(name);
      this.price = new SimpleDoubleProperty(price);
      this.amount = new SimpleIntegerProperty(amount);
      //this.ID=id;
  }
  
  public SimpleStringProperty nameProperty() {
      return name;
  }
  public void setName(SimpleStringProperty name) {
      this.name = name;
  }
  public SimpleDoubleProperty priceProperty() {
      return price;
  }
  public void setPrice(SimpleDoubleProperty price) {
      this.price = price;
  }
  public SimpleIntegerProperty amountProperty() {
      return amount;
  }
  public void setAmount(SimpleIntegerProperty amount) {
      this.amount = amount;
  }
  
  }
  </code></pre>
  
  <p>Now the "Add" button:</p>
  
  <pre><code>//Add Button function
      addButton.setOnAction(e-&gt;{
          Product product = new Product();
          if(checkString(nameInput.getText()).equals(""))
          {
              //break the whole process 
          }
          else
          {
              //value is correct, so it will be saved
              product.setName(checkString(nameInput.getText()));
          }
          //product.setName(checkString(nameInput.getText()));
          product.setPrice(checkDouble(priceInput.getText()));
          product.setAmount(checkInt(amountInput.getText()));
          table.getItems().add(product);
          nameInput.clear();
          priceInput.clear();
          amountInput.clear();
      });
  </code></pre>
  
  <p>You can see that I have 2 cases "setName". The first one is the with the "if" statement and how I want to do it, or how I thought of doing it for detecting when the process needs to stop. The second one is how it used to be and as you can see that Price and amount methodes are the same. Once I figure out how to do it for the Name property, I will do it the same with the Price and Amount properties.
  Here are the 3 check functions that I wrote:</p>
  
  <pre><code>public SimpleStringProperty checkString(String messageInput){
      SimpleStringProperty stringProperty = new SimpleStringProperty();
      try{
          Double.parseDouble(messageInput);
          System.err.println("You must input a proper name");
          stringProperty.setValue("");
          }
      catch(NumberFormatException e){
          stringProperty.setValue(messageInput);
      }
      return stringProperty;
  }
  public SimpleIntegerProperty checkInt(String messageInput){
      SimpleIntegerProperty integerProperty =  new SimpleIntegerProperty();
      try{
          integerProperty.setValue(Integer.parseInt(messageInput));
  
      }
      catch(NumberFormatException e){
          System.err.println("You must input a valid amount value");
          integerProperty.set(0);
  
      }
      return integerProperty;
  }
  public SimpleDoubleProperty checkDouble(String messageInput){
      SimpleDoubleProperty doubleProperty = new SimpleDoubleProperty();
      try{
          doubleProperty.setValue(Double.parseDouble(messageInput));
      }
      catch(NumberFormatException e){
          System.err.println("You must input a valid price value");
          doubleProperty.set(0);
      }
      return doubleProperty;
  
  }
  </code></pre>
  
  <p>At first, I wanted to make 1 "universal" check function but it seems to be impossible to do with Template types and etc. but that is another story.</p>
  
  <p>I would be really glad if anyone can help me, if you need other parts of the main code just ask, but I think that those are the relevant parts.</p>