methods of a JavaFX application from another application

Hallo.

So, I did some work on JavaFX 2.0 integrating graphics into a program called Max/MSP. It is a kind of Visual language for handling the music. Among it's features is the ability to write your own classes java, extended by the MaxObject class and create the custom components in your Max Patches. I received a MaxObject to launch a JavaFX applications, so I know that this part can be done. Now, I need two programs to talk properly with each other.

So, what I'm looking for is a pretty standard, reliable way to get ApplicationA, i.e. which launches application (and thusly can pass arguments by hand), to be able to transmit information in application B and vice versa. I'm assuming that someone else out there he wanted a JavaFX application to interface with another piece of java code. An Advisor on what should I look for in? Both applications are running on the same computer. And I hope my question is clear decently...
-Jean

Hey John,

I would like to try some of the following to refine your question:
* Put your launch within another thread code to see if that stops the problem of blocking
* use a random value that is passed to your application instead of 42 so that you can tell if new instances are created, etc.
call a different method for bang for your second call to the method just separate the flow to isolate your question

Something like:

public class MaxPart extends MaxObject {

    private boolean started;
    private Circles circles;

    public synchronized void bang()
    {
        if (!started)
        {
            outlet(0, "Starting Circles application...");
            started = true;
            new Thread()
            {
                public void run()
                {
                    Application.launch(Circles.class, null);
                    outlet(0, "Circles application launch completed");
                }
            }.start();

            // you could do some synchronized blocking here to wait for the instance to be set, try just doing a
            // simple sleep for now and add synch in if it works
            try { Thread.sleep(2000); } catch (InterruptedException e) {};

            circles = Circles.instance;
            Double randomValue = Math.random();
            outlet(0, "Circles assigned random value: " + randomValue);
            circles.setValue(randomValue);
        }
        else
        {
            outlet(0, "Circles is already started, not starting another one");
        }
    }

    public void anotherBang()
    {
        outlet(0, "Circles random value was: " + circles.getValue());
    }
}

Either way, you mention that you want to use the Singleton pattern. You pretty much are already - the 'instance' is a singleton that gets the value once (when the Application is launched) and is then used in the world. There is nothing real magic of singletons.

Also, just to let you know the 'main' method in your application of circles is not needed or used. The bang method directly calls the launch. You only need this main method if you want to run the standalone app of circles (which is still useful for testing).

Hope that helps,
zonski

Did you find this answer useful? If so, please indicate as 'correct' or 'useful '?

Tags: Java

Similar Questions

  • Call the method from another application

    Then. That is my question. Is it possible to call a method from another application, so I can get some data from this app?

    I know that I could also do this with persistent store, but I would like to do it this way.

    Thank you. I'll try with world events and TIME store.

  • import from another application page

    Hi, I'm using Apex 4.2.

    I want to import a page from another application. Is this possible in oracle apex?

    When I do export and import, it says this page is another application and can't install...


    Thank you
    Nihar Narla

    I tried the other day, the workaround is to create a new page in the constructor of the page and set it as a copy of another application - options in the first steps of the wizard.

    Scott

  • Get the value of the item application from another application

    Hello

    My apologies if this has been answered elsewhere, but it is very difficult to find something relevant when you are interested in the function V!

    My application consists of a number of different applications APEX that use the same cookie so that you can easily navigate between applications without having to log in again and to keep the same session id. Having separate applications allows to group pages and reuse the code easily.

    I have a requirement to be able to write the values stored in the fields in a single application to the database through a process on a page in another application. As a simplified example, that is to create messages and bookmarks of pages to display specific records in the database. The user will navigate through the system and find a record that they are interested, click on a button that displays a page from another application, enter in some details and then save the record in the database.

    The application of 'other' page knows the url of page called him, so that he knows also the application id and the page, but he doesn't know what file is being viewed. I can find the application and the page id is the name of the element that stores the primary key. I noticed that the V function also accepts the stream id, so it should be easy to then get the value by V (v_item_name, v_app_id). However it always returns null.

    I've simplified this by adding a page on the homepage (32561 application) process to insert a value in a table of test using a process page:
    insert into test values ('#'||V('P1_ID'));
    The result is #41
    So if I go to the page in the other application, I have a page process which is:
    insert into test values ('*'||V('P1_ID',32561));
    The result is *.
    I thought that maybe the other page of the application was ignorant of id flow, in that I spent, but change the above to:
    insert into test values ('*'||V('P1_ID',));
    The result is * 1 (the value of P1_ID in the other application)

    I'm doing something wrong? Have I misunderstood how the V function? Or is there another way I can retrieve the value of an element of application in another application?

    I am currently in 3.1.2, but I just tried this on apex.oracle.com (3.2) with the same results.

    Thank you very much
    Sara

    Hi Sara,.

    Have you seen the answer by Scott here -

    Re: Cross App State of Session

    Namely, using APEX_UTIL. FETCH_APP_ITEM

    APEX_UTIL.FETCH_APP_ITEM(
        p_item    IN VARCHAR2,
        p_app     IN NUMBER DEFAULT NULL,
        p_session IN NUMBER DEFAULT NULL)
    RETURN VARCHAR2;
    

    John.
    --------------------------------------------
    Blog: http://jes.blogs.shellprompt.net
    Work: http://www.apex-evangelists.com
    Author of Pro Application Express: http://tinyurl.com/3gu7cd
    AWARDS: Don't forget to mark correct or useful posts on the forum, not only for my answers, but for everyone!

  • First JavaFX application with time sequential process

    Hi all

    I'm working on my first JavaFX application.  I have a user (view) UI elements in place, I have a controller that works properly (with the exception that I will mention below), and I have a model that works properly (processes data correctly), but the model code was written to run under a user interface.

    What I want to do is the following.  When the user clicks on the "Run" button, the user input is passed to the model via the controller and the data is processed.  It's a do - once a sort of thing where the input is transformed into the output and that's the end of it.  The user interface can be reset and new entry provided, and all this happens again by clicking the run button.  Here's the problem: the treatment has several steps that need to occur in order, but some may take some time.  I want to provide feedback via a message (what is done) and overall progress via a progress bar (the two items in the current user interface).  The problem is that I am still very confused on how to accomplish the user comments.

    The user interface was built in SceneBuilder, and I attributed to the onMouseClicked event to call the runButtonClicked() method in the controller.

    The runButtonClicked() method calls the private methods that run the processing steps (I'll do something more intelligent exception - please ignore that for now)...

    public void runButtonClicked() {}

    runButton.setDisable (true);

    sdfFileBrowseButton.setDisable (true);

    outputFileBrowseButton.setDisable (true);

    try {}

    prepareSDFFile();

    prepareModels();

    collectDescriptors();

    makeSamples();

    evaluateSamples();

    writeResultsToTextFile (results, outputFile);

    } catch (IOException exception) {}

    System.out.println ("Caught an IOException:" + exception.getMessage ());

    } catch (JAXBException exception) {}

    System.out.println ("caught JAXBException:" + exception.getMessage ());

    }

    }

    Each of the calls in try-catch are tasks that need to be linked in the order listed.  Some of them may take a long time (for example, collectDescriptors(), evaluateSamples(), and writeResultsToTextFile().  The work is not done in the controller.  The controller creates instances of classes that do the actual work (this seems to be a departure from most of the tutorials I've seen - it seems the model and the controller are mixed in the tutorials).

    I would like to alert the user about this step is execution (by means of a message in the user interface) and at what stage of the process as a whole is in (through a progress bar).  It would be nice if the progress bar might reflect the status of each individual step (back to 0 at the beginning of the next step), but given the bar just reflect more all the advances (e.g., how many six steps were finished) would be sufficient.

    I also want to be able to manage a Cancel key event and just stop the whole process and reset the app (lose whatever work has been done is OK).

    -I can truly say what should be the best approach.  None of the examples in several tutorials, I went on that have really touched on this type of sequential process.  I would like suggestions.

    Thank you


    Dave.


    Suggested approach

    What you describe is a quite classic case to use the utility javafx.concurrent (task and Service).

    Your application is a perfect fit for the use of these services, which will provide you with:

    1. an execution thread concurrent to run your journal of the current process

    2. a feedback mechanism of thread-safe for the progress that you can link to a ProgressBar for interactive progress feedback.

    3. a feedback mechanism of thread-safe for messages that you can bind a label to your interactive status feedback.

    4 code example that illustrates the ability to cancel and restart the process.

    5, a setter callback method of success that can be configured to provide a result and decide on the success.

    6. a reminder Set accessor method failure which can be set to make an exception and to take measures in case of failure.

    Task and Service samples

    There are a lot of examples of tasks if you search for task of JavaFX.

    There are also great documentation in the javadoc task and Service .

    Here is an example of using a service of JavaFX.  The example is a bit old and uses does not use some new features of the API such as setOnSucceeded or setOnFailed, it also uses models of generator now frowned upon, however, the bulk of it is still relevant to what you want.

    Here is another sample more complicated to make 300 cards off screen and save the files in JavaFX, although I doubt that your task should be as complicated and probably a unique control service is all you need, in order to not pay too much attention to the more complicated example unless you need this kind of functionality.

    Here's another simple example for Re: create several parallel tasks into a single service, which shows in fact sequential and a side event of the stage of the tasks within a service.

    Progress can be reset between the steps, so that the message indicates the current step and progress indicates the status of the market rather than overall progress.  You can expose different processes for feeding of the overall progress back in addition to the progress of the step.

    For more help

    If you're still having problems, I'm sure someone on the forum could easily model a draft sample application illustrating the techniques based on the info you provided in your question, just ask if you would like that...

  • Can be de-compiled JavaFX applications?

    I'm a former developer of Silverlight and I just discovered JavaFX 2.0. I'd like to build some applications that would be delivered in browser applications, and I wonder about how secure my source code is a JavaFX application.

    In the world of Silverlight apps could be décompilés, so the best recommendation to protect your source code was using a utility of obfuscation. Would that be true here in JavaFX world too?

    JavaFX = Java. And Java classes can be décompilés, Yes. Obfuscation is the best way to protect the code; "do not give a hoot" is another. This has little to do with Silverlight or JavaFX, it's an inherent problem of applications that work under the customer they can be divided into. The only real way to protect against the theft of code is to do what you want to be protected on a server and display it as a service.

  • Menu item to exit a JavaFX application

    Hello. I am very new to JavaFX so please forgive what may be an obvious question.

    Can anyone provide a code example to create a menu entry for example, file-> exit to quit a JavaFX application?

    I can create the menus, but I don't know how to perform the actual output.

    Use the setOnAction method? What is the code performs the actual closing of the app?

    Thank you.

    Tony

    Hello. Here is an example:

    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.stage.Stage;
    import javafx.scene.control.*;
    
    public class MenuIt extends Application {
    
        public static void main(String[] args) {
            Application.launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) {
    
            MenuItem menuItem = new MenuItem("Exit");
    
            final Menu menu = new Menu("File");
            menu.getItems().add(menuItem);
    
            MenuBar menuBar = new MenuBar();
            menuBar.getMenus().add(menu);
    
            menuItem.setOnAction(new EventHandler() {
    
                @Override
                public void handle(ActionEvent e) {
                    Platform.exit();
                }
            });
    
            primaryStage.setTitle("Menu sample");
            Group root = new Group();
    
            Scene scene = new Scene(root, 300, 250);
    
            root.getChildren().add(menuBar);
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
    
  • How to set the position and size of the façade using the FPRunTimePosRunCustom method in a c# application?

    How to set the position and size of the façade using the FPRunTimePosRunCustom method in a c# application?

    I found a solution! -Set the size and position of the façade with the help of the

    File > VI properties > window running Position (in category list) > custom (in position of menu drop-down).

    then just accept the current position and size (leave the boxes checked) or set values you want directly (uncheck the boxes and fill in the numbers), or physically position and size the façade and use, the "set to current location" button and press "set size" current All that is easier for you.

    OK so it does not make use of the method VI Methods (Active X) FPRunTimePosRunCustom ([Position], [Size]) but if labview want to make him difficult to use then other means must be found.

  • I have problems with JavaFX applications run on raspberry pi!

    I have problems with JavaFX applications run on raspberry pi. I did all the steps of the course videos: overclocking, without comment that I had to uncomment on the framebuffer, but Exceptions are always produce. Demonstration of fireworks as an example does not work. Someone went through this problem? Java applications are ok. Like the versions of java in netbeans project and also on 'Properties' and they are all JDK 8. So if anyone can give a clue, I am very grateful!

    Can you provide the exceptions that you got so I can help you better?

    You want to make a coaching for this session?

    Vinicius-

  • JavaFX application: create a preload interface image

    Could someone tell me how create a preload bar view with a background image, while waiting for the appearance of the main interface of the program created by JavaFX application?

    Or give me a link to a related proceeding...

    Thank you for your response. My question has been fully answered!

  • How can I keep only one instance of the javafx application at the same time?

    Hello
    How can I keep only one instance of the javafx application at the same time?
    Let not the user run the javafx application is running on your PC.

    Hello. This program does what you want. You can probably find a better solution.

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileNotFoundException;
    import java.io.*;
    import java.nio.channels.FileLock;
    import javafx.application.Platform;
    import javafx.stage.WindowEvent;
    
    public class Simpleapp extends Application {
    
        public static void main(String[] args) {
    
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception {
    
            final File file = new File("flag");
            final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
            final FileLock fileLock = randomAccessFile.getChannel().tryLock();
    
            System.out.print(fileLock == null);
            if (fileLock == null) {
                Platform.exit();
            }
    
            primaryStage.setTitle("Hello World!");
            Button btn = new Button();
            btn.setText("Say 'Hello World'");
    
            StackPane root = new StackPane();
            root.getChildren().add(btn);
            primaryStage.setScene(new Scene(root, 300, 250));
    
            primaryStage.setOnCloseRequest(new EventHandler() {
    
                @Override
                public void handle(WindowEvent arg0) {
                    try {
                        fileLock.release();
                        randomAccessFile.close();
                        System.out.println("Closing");
                    } catch (Exception ex) {
                        System.out.print(ex.getMessage());
                    }
    
                }
            });
    
            primaryStage.show();
        }
    }
    
  • How can I implement a comfirmation window when closing the javafx applications?

    Hi, guys
    I would add a confirmation window when the user closes my javafx application, if the user clicks Yes, I close the application, so no, I wouldn't close it, how can I implement this feature?
     
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
    
                   @Override
                   public void handle(WindowEvent arg0) {
                        try
                        {
                             //todo
                        }
                        catch(Exception ex)
                        {
                             System.out.print(ex.getMessage()+"\r\n");
                        }
    
                   }
            });

    Hello. Here is an example:

    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Pos;
    import javafx.stage.*;
    import javafx.scene.*;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.*;
    import javafx.scene.control.*;
    
    public class ModalDialog {
    
        public ModalDialog(final Stage stg) {
         final Stage stage = new Stage();
            //Initialize the Stage with type of modal
            stage.initModality(Modality.APPLICATION_MODAL);
            //Set the owner of the Stage
            stage.initOwner(stg);
            Group group =  new Group();
            HBox hb = new HBox();
             hb.setSpacing(20);
            hb.setAlignment(Pos.CENTER);
            Label label = new Label("You are about to close \n your application: ");
            Button no  = new Button("No");
    
            no.setOnAction(new EventHandler() {
    
                public void handle(ActionEvent event) {
                       stage.hide();
                }
            });
            Button yes  = new Button("Yes");
            yes.setOnAction(new EventHandler() {
    
                public void handle(ActionEvent event) {
                       stg.close();
                }
            });
    
             hb.getChildren().addAll(yes, no);
             VBox vb =  new VBox();
             vb.setSpacing(20);
             vb.setAlignment(Pos.CENTER);
             vb.getChildren().addAll(label,hb);
            stage.setTitle("Closing ...");
            stage.setScene(new Scene( vb, 260, 110, Color.LIGHTCYAN));
            stage.show();
    
        }
    
    }
    

    Test:

       import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.stage.*;
    
    /**
     *
     * @author Shakir
     */
    public class ModalTest extends Application {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            Application.launch(ModalTest.class, args);
        }
    
        @Override
        public void start(final Stage primaryStage) {
            primaryStage.setTitle("Hello World");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
    
           primaryStage.setOnCloseRequest(new EventHandler(){
    
                   @Override
                   public void handle(WindowEvent arg0) {
                                    arg0.consume();
                        try
                        {
                         ModalDialog md = new ModalDialog(primaryStage);
                                    }
                        catch(Exception ex)
                        {
                             System.out.print(ex.getMessage()+"\r\n");
                        }
    
                   }
            });
    
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
    
  • How to copy contact from another list? No traveling.

    How to copy contact from another list? No traveling.

    Same way you do in most of the applications when you use slide it / move. You hold down the CTRL key while dragging the file or contact. You will see a sign more seem to indicate a copy and not move. Hold the control key until releasing the contact in the new location.

  • I need to download an app from another app store

    I recently changed my cellular service provider to a provider of alacarte then to the Japan. I have three phones on their family plan.

    To receive the (substantial) discount for the members of the family calls, you must install their app on your phone. Therefore, to use the service.

    The app is located in the Japan App store which I can't access any of my devices because they are related to my iCloud US account.

    (1) how can I access the Japan Bank to download the free app without destroying them completely everything related to my AppleID us?

    (2) is it possible to copy the application from another computer that IS connected to the Japan App store? Or it will mess up something?

    Thanks for all the ideas.

    all purchases are always related to the appleID never to a computer or an ios device

  • Installation OTA / app from another provider

    I am experiencing very strange behaviour when I want to install my application via appworld and a 'special' from another provider app already installed and visa versa.

    On OS7 devices these two applications can be installed at the same time.

    If an application is already installed another app it is preponderant.

    Appworld still wondering whether to replace the old/other version.

    But there is no older/other versions it is a different application!

    I can tell versions its show me.

    Doesent matter if I click Yes or no the already installed application is replaced by the soft, I tried to install.

    But his past just on OS7 devices. On older devices, it works like a charm!

    This is expected if both applications used the same library and both are using it as a shared library.

    In this case, when you install an application, the library of the other application is overwritten.  The application itself should remain.

    You can avoid this by using a bundled library.  Learn more about this here: working with libraries - shared, packed, releasing and using 3rd Party software development kits

Maybe you are looking for