-2

I am creating server/client application. The server and client parts should be written in C language. However, for user interface I would like to use javafx. So, the question is it possible to combine javafx with C? If it is, then how do i do this in a proper way?

2
5

Nope, JavaFX is a Java API. You cannot use it from C. While you can use C and Java in the same process e.g. by creating JNI bindings, that requires substantial development effort and implies some performance overhead, as JNI has to copy all data between its C representation and its Java representation. It would likely be much easier and result in a much more stable program, if you either

  • write your client completely in Java, or
  • write your GUI in C or C++ as well.
0

So you are writing a program in C (your client code probably) and you want to add some user interface to it.

Notice that the C11 standard (read n1570) provides very limited features for user interaction (basically, program arguments and <stdio.h>). You probably want to use some external library, which usually would be operating system dependent.

You could at first consider making a command line program. Then your C program simply parses the program arguments given to it (i.e. arguments to main) and act accordingly. Even that is often OS specific, but this answer provides some guidance. FYI, the GNU Glibc library documentation has a chapter on parsing program arguments.

You might also define some syntax and semantics for your standard input, and use common parsing techniques on it. You could use recursive descent parsing techniques. But that might not be very user friendly (because your user could not easily edit his/her input).

On many systems, the user could interact with your program thru a terminal emulator (which is much more complex than what <stdio.h> provides). On Unix or POSIX systems, read about the tty demystified, and use libraries like termios(3) or preferably ncurses (or at least readline).

You could consider providing some GUI. In practice, you then need to use some toolkit, like GTK (or Qt in C++) or libSDL.

You might expect your user to use his/her web browser. Then you want to add some Web interface. For that, you should make your C program a specialized web server, using some HTTP server library like libonion or libhttp. Of course, you then need to be familiar with web technologies, including HTTP, HTML5, CSS, AJAX.

Since you mention JAVAFX in your question, you might split your software in several processes doing inter-process communication (then you would have a user interface program written in Java communicating with your C programs; how that is achieved is operating system specific).

Not the answer you're looking for? Browse other questions tagged or ask your own question.