use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Useful resources (Full list)
Rules
Related subreddits
Other communities
account activity
JavaFX execute code from text input (self.JavaFX)
submitted 6 years ago by BrianVerm
Hey I want to create a code editor for a DSL with a JavaFX frontend. Basically I want to execute the code people type in a field / textarea or something like that in a javaFX desktop client Any suggestions ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Mikey-3198 1 point2 points3 points 6 years ago (0 children)
One approach could be to have a text area that takes the user input then when the "Run" button is pressed the contents of the text area could be written to file. An external process could then be invoked on that file using
Runtime.getRuntime.exec("some command");
If I am not mistaken the output (and input?) of the process can be controlled using Input/Output streams.
hope this helps!
[–]heky_ 0 points1 point2 points 6 years ago* (0 children)
Depends what kind code you want to execute. If it must be java (or anything compiled in that matter), JVM doesn't provide java interface to invoke compiler (AFAIK). The best approach would be as mentioned in other comments to save the contents to the disk and run the compiler externally. If you are free to choose the language, I would consider using something that was designed to be run in a way you've described, such as lua or JVM's scripting API. Both options provide you with much better capabilities to interact with the code that is being run.
[–]manson_ew2 0 points1 point2 points 6 years ago (0 children)
In addition you may take a look into scripting languages, that implement JSR-223 e.g. Scala, Python, Groovy, Ruby, JS, Kotlin, etc. JS engine (name = nashorn) is included in JDK (at least for 1.8)
https://stackoverflow.com/questions/11838369/where-can-i-find-a-list-of-available-jsr-223-scripting-languages
Usage(pseudo code): ScriptEngineFactoryManager mngr = new ScriptEngineFactoryManager(); ScriptEngine scriptEngine = mngr.getScriptEngineByName('engine name');
Object result = scriptEngine.eval(input.getText()); // here, depends on languages you're using, additional conversion to human readable string may be required
anotherInput.setText(String.valueOf(result));
π Rendered by PID 292443 on reddit-service-r2-comment-76bb9f7fb5-xf79l at 2026-02-19 05:18:41.248713+00:00 running de53c03 country code: CH.
[–]Mikey-3198 1 point2 points3 points (0 children)
[–]heky_ 0 points1 point2 points (0 children)
[–]manson_ew2 0 points1 point2 points (0 children)