如何从actionEvent中的另一个类调用boolean方法?

时间:2019-02-16 22:01:14

标签: javafx fxml netbeans-8

不确定Im是否可以在Controller中正确调用该方法,也不确定是否可以从抽象类中获取。

这是我的控制器类:

   /**
   * Open a browser at the given URL using {@link Desktop} if available, or alternatively output the
   * URL to {@link System#out} for command-line applications.
   *
   * @param url URL to browse
   */
  public static void browse(String url) {
    Preconditions.checkNotNull(url);
    // Ask user to open in their browser using copy-paste
    System.out.println("Please open the following address in your browser:");
    System.out.println("  " + url);
    // Attempt to open it in the browser
    try {
      if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Action.BROWSE)) {
          System.out.println("Attempting to open that address in the default browser now...");
          desktop.browse(URI.create(url));
        }
      }

Part_abstract类中的库存类调用方法:

    Part_abstract partSelected;
    Product productSelected;


    Inventory esisInv = new Inventory();

    @FXML void deletePartMain(ActionEvent event) {
    if (partSelected != null && partTable.isFocused()) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle("Caution!");
        alert.setHeaderText("Are you sure you want to delete Part ID # " + partSelected.getPartIDTable() + " ?");
        alert.setContentText(null);

        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == ButtonType.OK) {
            try {
                for (Part_abstract pa : esisInv.parts) {
                    if (esisInv.deletePart(pa) == true) {
                        pa = partSelected;
                        partTable.getItems().remove(partSelected);
                    }
                }
            } catch (Exception e) {
                System.out.println("This is wrong. HA!");
            }
        }
        //else if 

0 个答案:

没有答案