Start JavaFX application from Java
Hello,
I have the following scenario:
I have a small JavaFX application and a big Java application. Now the Java App should call the JavaFX App to start up.
Further the JavaFX App has to call some methods from the Java App. Is this possible?
What is the best approach for my scenario?
Maybe somebody has made some experiences ..
thanks!
Edited by: 799878 on 03.11.2010 07:54
"Now the Java App should call the JavaFX App to start up."
I'm assuming that the JavaFX code and the Java code are in the same application, correct? If so, then there are hacks available, but no standard way to start up JavaFX from Java will exist until the APIs have been ported from JavaFX script to Java.
"Further the JavaFX App has to call some methods from the Java App. Is this possible?"
Yes. Java can be called from JavaFX just fine. Just be careful if you use multi-threading or time consuming operations, since JavaFX script is apparently single threaded. Also be aware that netbeans normally compiles JavaFX applications with JSE version 1.5, so library features that did not exist until later versions will not be available by default.
Similar Messages
-
Launching applications from java code
I have found a solution to launch applications from java.I thought this will be useful for programmers who want to open a
1. Browser
2. Player
3. Files etc.
There are 2 solutions :
I)To use a known application :
eg: to open windows media player
String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "START MPLAYER2.exe "+mediaURL+" /PLAY /CLOSE /FULLSCREEN";
//eg: mediaURL = "\"D:/project/songs/track1.mp3\""
// /PLAY /CLOSE /FULLSCREEN this option can be used only for windows media player
// for any other application use cmd[2] as START apl.exe //apl can be any windows application
Process p = Runtime.getRuntime().exec(cmd);
II) To use a default application:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
// url can be any url
ref: [http://forums.sun.com/thread.jspa?threadID=5203313|http://forums.sun.com/thread.jspa?threadID=5203313]
[http://www.ericphelps.com/batch/rundll/|http://www.ericphelps.com/batch/rundll/]
Edited by: veda_sishta on ? ?????, ???? ??:?? ???????
Edited by: veda_sishta on ? ?????, ???? ??:?? ???????To post code, use the code tags -- [code]Your Code[/code] will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
And make up your mind what file type you're having a problem with. Maybe .asx doesn't have a file association on your computer.
This works just fine for .m3u:import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Playlist {
public static void main(String[] args) {
try {
Desktop.getDesktop().
open(new File("E:/Music/Playlists/test.m3u"));
} catch (IOException ex) {
ex.printStackTrace();
}db
edit Did you try searching the net for the error you got? ("Invalid menu handle")
Edited by: Darryl.Burke -
How to call a VB application from Java
Hi,
does anybody know how to call a VB application from java.
Would appreciate if you can provide me with an example.
thankstry exec()ing the cad program with the name of the file as a command line parameter...
Runtime.getRuntime().exec("CADProg.exe Test.prt");
i have no clue if this will work but it seems like it's worth a try. -
Hi all
I have opened an application say MSWORD from my java class using Runtime.getRuntime(), Now on close button i need to close the application and on the save button of the application i even want to save the application from java command
The question is HOW????
please reply,
Thanx,
Amittcan I open the konsole from java??Yes.
First you must figure out how to do that from the command line yourself. That has nothing to do with java.
Note that that how you do that MUST account for the fact that the "command line" is actually a shell. Some commands must be run by running the shell as the actual command and then passing the desired command as an option to the shell (the actual command.)
Again you can google for examples. -
Start an application from console with arguments
Why do I get an ArrayIndexOutOfBoundsException when I try to start the application with
> java Application 12345
public static void main(String[] args)
String host = args[0];
String port = args[1];
if(port.length() == 0)
port = "500";
System.out.println(host+"\n"+port);
}I have modified the main method and here it is. My problem is described below the code.
public static void main(String[] args) throws IOException
String host;
int port;
if(args.length == 0)
host = "address.to.server";
port = 1000;
else if(args.length == 1)
host = args[0];
port = 1000;
else
host = args[0];
try
port = Integer.parseInt(args[1]);
catch (NumberFormatException ioe){ port = 1000; }
try
new Client(host, port);
catch (ConnectException ce){ System.out.println(ce.getMessage()+" "+host+" "+port); }
catch (NullPointerException npe){ System.out.println(npe.getMessage()+" "+host+" "+port); }
}If I try to start the program through
> java Clientthe connection is set up to host = "address.to.server"; port = 1000; and the program works.
If I try to start the program through
> java Client localhostI get Connection refused: connect localhost 1000
If I try to start the proram through
> java Client localhost 1000I get Connection refused: connect localhost 1000
If I connect to a host that doesn´t exist, like
> java Client localho 1000I get null localho 1000
I have no Idea what´s wrong.
Please, help! -
Start java application from java program
My problem is the following:
I start a java application A that allows you to select a couple of .java files.
After having choosen them, the application adds some additional information to these .java files (that means some more lines of code � we call it �infecting� the java files).
After the files have been infected, I want to start the application B implemented by these choosen and infected .java-files (without a new start of the Java Virtual Machine)
For doing so, we use the following method whichs works quite fine:
public static void ExecuteWithInvoke(String path, String classname)
try
new URLClassLoader(new URL[] {new File(path).toURL()})
.loadClass(classname).getMethod("main",
new Class[] { String[].class }).invoke(null,
new Object[] { new String[] {} });
catch (Exception e)
{e.printStackTrace();}
The only problem that occurs:
When the application B is launched, the �old� version of the choosen .java files is used and not the current, already infected version of these files. (I guess because the �old� .class files are used.)
I solved this problem by finishing the program A after the infecting and restart my application B manually. In this case the infected .java files are used (I guess the new Start of the Java Virtual Machine solves my problem by reloading the �new� .class files)
How can I reach to start my application with the mentioned method but with the infected .java files and without having a new start of the JVM ??
Can anybody help me?
Thanks in advance
Sorry for my English, it�s a long time since I quit schoolHello,
my problem of reloading classes is still unsolved although you tried to help me!
Therefore I posted a little program to illustrate our difficulty.
It would be nice if somebody could have a look at this program.
We have a file Testdatei.java whose only method is the main method.
I get the class object of this file and with the help of Reflection the declared methods.
Evereything works fine so far.
Then I change the content of this file by adding an additional method a() (see change() for this).
Now I delete the old class file and I compile Testdatei.java again (see compileJava()) and once more I get the class object for this changed file. Afterwards I get the declared methods for this class via reflection.
But instead of showing now the methods main() and a() Reflection still only shows the method main().
I guess the changed class has not been reloaded!!
package testpackage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import com.sun.tools.javac.Main;
public class LoadClass
private File f;
private Class c = null;
private Object o;
public LoadClass()
f = new File("C:/AAJ/src/testpackage/Testdatei.java");
try
o = neuesExemplar(f.getPath(), "testpackage.Testdatei");
c = o.getClass();
System.out.println("Class " + c.getName() + " found.");
catch (Exception e)
{e.printStackTrace();}
Method [] method = c.getDeclaredMethods();
for (int i=0; i<method.length; i++)
System.out.println(method.getName());
change();
compileJava(f.getPath());
File fileToDelete = new File("bin/testpackage/Testdatei.class");
System.out.println(fileToDelete.delete());
Class cla = null;
try
Object o = neuesExemplar(f.getPath(), "testpackage.Testdatei");
cla = o.getClass();
System.out.println("Class " + cla.getName() + " found.");
catch (Exception e)
{e.printStackTrace();}
Method [] methods = cla.getDeclaredMethods();
for (int i=0; i<methods.length; i++)
System.out.println(methods[i].getName());
private int compileJava(String javaFile)
String[] args = {"-d", "C:/AAJ/bin/", "-classpath", System.getProperty("java.class.path"), javaFile};
return Main.compile(args);
public static void main(String[] args)
new LoadClass();
private Object neuesExemplar(String pfad, String klassename) throws Exception
URL url = new File(pfad).toURL();
URLClassLoader cl = new URLClassLoader( new URL[]{ url });
Class c = cl.loadClass(klassename);
return c.newInstance();
private void change()
FileWriter fw;
BufferedWriter bw;
try
fw = new FileWriter(f);
bw = new BufferedWriter(fw);
bw.write("package testpackage;");
bw.newLine();
bw.newLine();
bw.write("public class Testdatei");
bw.newLine();
bw.write("{");
bw.newLine();
bw.write("public static void main (String [] args)");
bw.newLine();
bw.write("{");
bw.write("System.out.println(4);");
bw.newLine();
bw.write("}");
bw.newLine();
bw.newLine();
bw.write("private void a ()");
bw.newLine();
bw.write("{");
bw.newLine();
bw.write("System.out.println(55);");
bw.newLine();
bw.write("}");
bw.newLine();
bw.write("}");
bw.close();
fw.close();
catch (IOException e)
{e.printStackTrace();}
I�m using eclipse 3.1.0. Is it possible that it�s a bug in eclipse that eclipse holds the old class file in memory from the beginning and always refers to this one and not to the new compiled one?
Thanks a lot
Simon -
How can I invoke JavaFX application in Java project
I want to set an actionlistener on a button.When I click the button,it will run the JavaFX application.
Any idea?Thanks in advance.A program that launches JavaFX programs? Something like this might work:
* Launches the given JNLP file.
* @param jnlpFileURL The url to the JNLP file of the JavaFX application we are launching.
public void launchFXApplication(String jnlpFileURL) throws Exception {
//Retrieve the runtime.
Runtime runtime = Runtime.getRuntime();
//Create the commands we will be executing.
String[] commands = new String[] {
System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaws",
jnlpFileURL
//Execute it.
final Process process = runtime.exec(commands);
//Need to read the input.
final BufferedReader errorReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
final BufferedReader outputReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
//Input MUST be read and should be done in separate threads.
Thread errorThread = new Thread(new Runnable() {
public void run() {
String line;
try {
while ((line = errorReader.readLine()) != null) {
//Examine it if you like. Optional.
errorReader.close();
} catch (IOException ex) {
ex.printStackTrace();
Thread outputThread = new Thread(new Runnable() {
public void run() {
String line;
try {
while ((line = outputReader.readLine()) != null) {
//Doing something with the input is optional.
errorReader.close();
} catch (IOException ex) {
ex.printStackTrace();
//Run the separate threads.
errorThread.start();
outputThread.start();
//Wait until it's done.
process.waitFor();
}This code will of course need to be signed if you intend to launch it as an applet or via webstart.
Edited by: aidreamer on Aug 14, 2011 8:35 PM -
How to launch an application from java?
Hi,
Would anybody please help me this. I need to launch a new desktop application from my java app but I don't know how. For example, when user clicks on a "Edit" button from my java app, my app needs to launch NOTEPAD.EXE to allow user starts editing.
Thanks a lot.
Hung.try something like this for your button's action method:
String[] cmd = {"notepad"};
Runtime rt = Runtime.getRuntime();
try {
Process pro = rt.exec(cmd);
pro.waitFor(); // wait until it's done executing
System.out.println("Process exit code is: " + pro.exitValue());
}catch(IOException ioe) {
System.err.println("IOException -> " + ioe);
} catch(InterruptedException ie){
System.err.println("InterruptedException: " + ie);
} -
Invoking JavaFX script from Java
Hi,
Just started working on javafx and got the error below while trying to invoke javafx from java.
/******************** my java code *************************/
package fxexamples;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleScriptContext;
import javax.swing.SwingUtilities;
public class RunFX {
public static void main(String[] args) {
final DataObject myObj = new DataObject();
Runnable fxScript = new Runnable() {
public void run() {
ClassLoader loader = Thread.currentThread()
.getContextClassLoader();
ScriptEngineManager manager = new ScriptEngineManager(loader);
ScriptEngine engine = manager.getEngineByExtension("fx");
String script = "import fxexamples.FXtoJava;";
try {
engine.eval(script);
} catch (Exception ex) {
ex.printStackTrace();
SwingUtilities.invokeLater(fxScript);
/*****************my fx file **************************/
import javafx.stage.Stage;
Stage {
title: "Die, Ajax! - Hello World"
width: 250
height: 50
/*******************stack trace********************/
javax.script.ScriptException: compilation failed
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.parse(JavaFXScriptEngineImpl.java:260)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:149)
at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:140)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at fxexamples.RunFX$1.run(RunFX.java:30)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Thanks in advance.I too, am having problems with using JSR-223 to use JavaFX script from within Java, specifically using Java FX 1.1 and Java 6. Please see:
http://forums.sun.com/thread.jspa?threadID=5373145 -
Starting weblogic server from java program
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd /c d:/bea/weblogic700/server/bin/setWLSEnv.cmd");
when ihave given like this it is working.
now i want to start weblogicserver from jav program
String s="-Dweblogic.Domain=mydomain weblogic.Server"
Process p=r.exec("cmd /c d:/bea/weblogic700/server/bin/setWLSEnv.cmd java "+s);
when i gave like this weblogicserver should start with specified domain
but no output is comming.please tellme where the problem isno - nothing happened. it perform the next java code - and there is nothing else happen on the windows.
maybe i don't check in the right place for the error you are talking about?
i also tried i simple cmd file that does nothing - but still nothing...
for any other file types it works properly. -
Calling javaFX script from Java program
I am trying to call JavaFX script from a simple Java program. code as follows:
import java.io.*;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class My{
public static void main(String[] args) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("fx");
try {
InputStreamReader reader = new InputStreamReader(My.class.getResourceAsStream("first.fx"));
engine.eval(reader);
reader.close();
} catch (Exception e) {
e.printStackTrace();
my first.fx file code is here:
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
Stage {
title: "My First JavaFX Sphere"
scene: Scene {
width: 250
height: 250
content: [
Text {
font: Font { size: 24 }
x: 20, y: 90
textAlignment: TextAlignment.CENTER
content:"Welcome to \nJavaFX World"
} //Text
] // content
} // Scene
} // Stage
I am not able to run My.java. runtime error as follows:
java.lang.NullpointerException
Kindly correct me, where I am wrongI am able to call .fx file from Java. Thank you all for helping me to resolve this problem
Regards,
Ritu -
How to execute another application from java ?
I want to execute another application ( not java ) from my java application. Is it possible ? How can we do it ? Please guide me...
thanxHi littlestuart,
Yes it's possible.
Your question is frequently asked, please search the forum or google for an answer.
/Kaj -
Running a Linux application from Java
Hy,
I am working at a faculty project and I need your help
What I want to do is by clicking a button, in a JFrame I want to open an application ,for example Mysql Query browser. I am using FC 6 and Netbeans 5.5
Can you help me??
Thankscan I open the konsole from java??Yes.
First you must figure out how to do that from the command line yourself. That has nothing to do with java.
Note that that how you do that MUST account for the fact that the "command line" is actually a shell. Some commands must be run by running the shell as the actual command and then passing the desired command as an option to the shell (the actual command.)
Again you can google for examples. -
How to run Other application from Java
I want to run other applications such as IE.exe, notepad.exe from Java? How can I run?
Dear Friend, the following is the code to open IExplorer from Java Program
class RunTimeTest {
public static void main(String args[]) {
try {
Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe");
catch(Exception e) {
[\code]
ALL THE BEST
Shiva -
How to call msword application from java program
hai every body
i want to know about OLE in java.
how can i invoke msoffice application in java code.
if any body have sanple code for this post for me
thank youThere are some bridges available ...
http://www.google.com/search?q=ole+java+bridge
Maybe you are looking for
-
Error message: Sail library met some error
Hi there, I came across this error in the roboEngine error log: Sail library met some error, MsgID: 25, Msg: ERROR_INTERNAL. I also have a whole bunch of errors relating to older projects that no longer exist: - Fail to create IFilter object - Cannot
-
Music has disappeared from iTunes and from my external hard drive
I store my music on 2 separate external hard drives. I have a lot of music and didnt want to choke my system drive. I do not have iTunes organise my folders. I have a lot of classical and iTunes doesnt understand classical music. I began to notice a
-
Tax Update and Forced Tax update
Hi all, Plz can anyone explain me what is the difference between Tax Update and Tax Forced Update. Thank you, sam
-
Approvals for transporting XI objects
Does anyone have documentation on how your companies are handling approvals for transporting XI objects? I need to prepare a change management document that will be SOX compliant and wanted to know how everyone else is handling approvals? Any suggest
-
CM: Open Reconciliation Interface CE_999_INTERFACE_V
what are these columns for: Cleared_charges_amount Cleared_error_amount are they for tolerance? how does it work?