
09-05-2008, 05:07 PM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 3
Rep Power: 0
|
|
interface C programming with Java
I have designed an application, whenever I press a button it should execute the c code in the same folder how to achieve it?
|
|

09-06-2008, 05:05 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,452
Rep Power: 8
|
|
|
You will need to compile the C-code with the correct settings and interface it with Java using JNI. There are tutorials on this, but understand that this is not trivial programming and will take some work to get to understand.
|
|

09-06-2008, 03:32 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
|
|
|
Quote:
|
|
execute the c code
|
If the c code is executeable from a command prompt, then you could use the Process and Runtime classes to execute it from a java program.
|
|

09-07-2008, 07:27 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 3
Rep Power: 0
|
|
Tell me the step by step procedure
I have developed the c program on linux and I have j2se installed on my windows now I need To make a GUI wrapper to the c program, which will do good with linux and windows both... 1st help me so that i can develop the same/application on XP, tell me the step by step procedure to achieve the same.
Do I need and c compiler with java?
|
|

09-07-2008, 07:38 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,452
Rep Power: 8
|
|
|
Quote:
|
|
I have developed the c program on linux and I have j2se installed on my windows now I need To make a GUI wrapper to the c program, which will do good with linux and windows both... 1st help me so that i can develop the same/application on XP, tell me the step by step procedure to achieve the same.
|
You really don't understand the magnitude of what you are asking here. Let me help you. Go to these tutorials on JNI:
CodeProject: JNI Basics - 1. Free source code and programming help
Chapter 5: JNI Technology
Java Native Interface: Programmer's Guide and Specification
Read and study them, and then come back in about a month, maybe longer.
Also, one more thing: using JNI often breaks your program's platform independence.
Lots of luck.
Last edited by Fubarable; 09-07-2008 at 07:40 AM.
|
|

09-07-2008, 07:51 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 3
Rep Power: 0
|
|
If that is so hard....
Sorry Fub for askin you a qn with such a big answer, if making it in java is so tough then could you suggest me a better way to have a gui wrapper for c in linux?
and tell me the same if I do it for windows?
Simplicity of the wrapping language is one of the preferences.
|
|

09-07-2008, 08:01 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,452
Rep Power: 8
|
|
|
Let me correct myself. If you are a wiz at C++, then you'll probably catch on to JNI pretty quickly. Us mere mortals may take longer.
|
|

09-07-2008, 03:15 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
|
|
|
How do you plan to communicate between the C program and the java program? Will the interface require more than what would go on a commandline or be printed to a std out?
|
|

09-11-2008, 06:09 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 7
Rep Power: 0
|
|
|
Hi,
Try using swig.I cant post the link cos the the forum only allows you to post a link once you make 20 posts. But just google for Swig, you should be able to find it easily. Using Swig, it can easily convert C/C++ code into java by generating the JNI for you. Isnt that great.
I have used it to interface my C++ code with Java Swing.
Hope it helps.
Cheers
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 10:43 PM.
|
|
VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org