0

I've been trying to work on an assignment but I've hit a roadblock. So I'm suppose to create a gui using JavaFX without the help of Scenebuilder. Let me explain what I'm trying to do.

I've set up two stages, primaryStage and secondaryStage. primaryStage has a button while secondaryStage has the textArea. So I've set the button's action to switch from primaryStage to secondaryStage using:

btnINV.setOnAction(e ->
            {
                secondaryStage.show();
                primaryStage.close();
            });    

But, what I'd also like to do at the same time is when the button is clicked, it would run a method that would also print some things onto the textArea. Here's the method I'm trying to use:

   public static void printStock()
    {
        System.out.println("---Food & Drinks Inventory Edit---");
        System.out.println("\nNo\tItem Name\t\tType\t\t\t\tStock");
        System.out.println("------------------------------------------------------------------");

        for (int i = 0; i < item.length; i++)
        {
            System.out.print(i + "\t");
            item[i].showmenu();
        }
    }

while showmenu(); being a method in another java file that does:

public void showmenu()
    {
        String x = null;
        switch (this.type)
        {
        case 'a':
            x = "Meat\t\t\t";
            break;
        case 'b':
            x = "Oil, Vinegar & condiments";
            break;
        case 'c':
            x = "Seasonings\t\t";
            break;
        case 'd':
            x = "Canned Items\t\t";
            break;
        case 'e':
            x = "Grains\t\t\t";
            break;
        case 'f':
            x = "Fridge Basics\t\t";
            break;
        case 'g':
            x = "Fruits\t\t\t";
            break;
        case 'h':
            x = "Vegetables\t\t";
            break;
        }

        System.out.println(this.name + "\t" + x + "\t" + this.stock + " " + this.msm);
    }

I'm really quite stumped at what to do from here on out. I'd figured that maybe I'd change the method from void to String and try to return something that way but I've no idea how.

  • See my answer to [this question](https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml/51050736#51050736). Perhaps that will lead you in the right direction. While it DOES use FXML, the controllers will demonstrate how to pass data between two different stages/controllers/classes. – Zephyr Nov 18 '18 at 15:37
  • @Zephyr FXML works a bit different right? When I tried using FXML I was able to get the method to print out onto the textArea, but despite that I couldn't figure out how to do the same with plain JAVAFX. – Delta Tango Nov 20 '18 at 07:39

0 Answers0