Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to make a desktop GUI that interacts with the user's files (with permission of course). My code to download files and put it in the user's choice of directory is all written in python. There is much more to this code, but everything is written in python.
I want the GUI part to be a desktop app, so the client can easily interact and function the program.
I want to make this GUI in java and have it interact with the python code once someone presses a button.
What are the best approaches to make this happen?
I would do it like this:
Process p = Runtime.getRuntime().exec("python app.py");
You can also pass arguments into the python program as command line arguments, like this:
Process p = Runtime.getRuntime().exec("python app.py arg1 arg2");
You might be interested in jython
http://www.jython.org
Also, you might think about running Python using JNI - this way, you will be able to keep the state of Python process while still being inside Java:
https://github.com/mkopsnc/keplerhacks/tree/master/python
Everything heavily depends on what you really want to achieve.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to create a graphical user interface (GUI) using Swing in Java.
The part I am kind of stuck is, I am planning to display some values from my Python program to the interface I am developing in Swing. I have looked up in forums and came across the Jython thing, but not quite sure on how to proceed with this, anyone information in this issue would be helpful to me.
Some extra information, if it may help, I have a set of sensors reading some values using a Raspberry Pi, and the sensors are operated using a Python script running in RPi. Now my goal is to develop a GUI using Java so that I can display those values from the Python script to the swing interface.
Thanks in advance.
I think your easiest path forward would be to store the values that are collected by the Raspberry Pi in an intermediary storage. This can be as simple as a text file, or if you want something more verbose, you can store it in a RDBMS or NoSQL DB. Then it becomes easier for the java application to look up the values without having to interface with Python.
If you want to directly interface with Python, you could look into GraalVM which has limited ability to directly execute Python code.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a working java app and now I would like to extend it to be controlled over ssh. Let's say I have a swing button that increases a counter. I would like to be able to ssh in that computer and say something $: myapp increase and have the button's action listener executed.
Maybe I'm using the wrong keywords but I could not find a solution. The 'kinda' solution I could think of is using signals but I'm not even sure if they can be used as I am used to from C and if that can be done without knowing the actual process ID.
Any material that can get me started would be welcome.
signals are hard to read from java, because there is a lot of difference between OSes on how to do those (some don't even have the concept), and java is designed to expose anything that can be generalized across all OSes java runs on, and to not expose anything that might not be there.
The usual way to do it, is via TCP/IP (so, java.net.Socket), or HTTP (so, jetty or some such).
Note that webapps can trivially be accessed remotely and can be scripted fairly easily. You could also consider building a command line / terminal based app, for example with lanterna which you can shove into a terminal session keeper / eternal SSH kinda deal.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have heard sometimes that the front end of a program was written in language A and the back end in language B. Can i do it for desktop programs I make too? Like do the graphics with Java and the back end with C or C++. How do i do it?
PS. Sorry if its a newbie question because I am one.
edit 1
Because i am told that my question is too broad, here is what I exactly want. How can I link mt action listener in java with a C program? For example, if i have a button "next hundred primes" i want the button to be made in Java and primes calculated using C.
This can be done in one Java process with JNI, for example. Java effectively calls C++ as a library.
This can also be done multi-process by having Java process create a C++ process then capture its output as, for example, C++ process exit code, standard output or created file.
A third way to do this would be to have a long-running C++ process listen on a TCP socket then have the Java program communicate with its C++ back-end over the network, either on the same machine or across an intranet.
Other methods also surely exist. These are just a few I know off the top of my head. :)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have written a fully functional chat program in C. The server starts up and allows multiple clients to connect and talk to each other, all via command line. However I would like to try adding a GUI to this program, but all of the C/C++ GUI packages seem to have a steep learning curve just to get started. Is there any way to write a GUI using Swing and connect it to the C code underneath?
For example, I would like to type some text into a box, click "send" and have it call the C function which deals with sending text. Is this possible? And if so, is it very difficult?
I can provide code if needed. I am also open to suggestions on which C++ GUI package might be most appropriate for this kind of program.
Yes, its possible. You would have to use JNI. You should really consider the learning curve of doing JNI vs learning whatever GUI framework you want to use you C/C++.
As someone who has done this on multiple professional projects though, I really would warn against it. It can produce very hard to find bugs.
Tcl/Tk Used to be the scripting language of choice if you wanted to provide a bunch of C/C++ methods with a (not too complicated) GUI. Python also provides GUI element via PyQT and PyKDE. I think it's much easier to use a scripting language like this to bind to C then trying to do Swing<=>C/C++ bridging.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Can you program external application from Java app.?
I know this is a wierd question but lately I really need to do it.
So the lets say I have "VLC" player or MPC or whatever it is, I want to be able to create a Java/C++ application or whatever it is to control the application such as play the video, pause the video and stuff.
If it possible please let me know and how.
It's certainly possible with VLC. Look here: http://wiki.videolan.org/Java_bindings as well as here: how to control VLC by java
For MPC, I don't know of any resources that can be used to do so. You can at least launch it to the best of my knowledge.
To start (execute) an external application you should use Runtime.getRuntime().exec(params);
or ProcessBuilder class.
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
See Execute external program in java for more information.
To send key strokes to another application you could use the "Robot" class (http://docs.oracle.com/javase/6/docs/api/java/awt/Robot.html).
What is expected is to have access to interface to do these operations, you can get some references from http://caprica.github.io/vlcj/
This is java api for controlling the VLC instance embedded in AWT.
I have found this site that describes how to run external programms from java
http://www.rgagnon.com/javadetails/java-0014.html