-2

So I'm thinking about making a GUI. My friend told me he knew how to do it in C#, so I went that method in setting the GUI up. Is there anyway to get a C# made GUI usable in java?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Scaream
  • 13
  • 1
  • 6

6 Answers6

5

Yes you can. You absolutely should not. I once wrote a perl application that used a VB GUI that i made, they communicated via OLE.

This is probably the worst construct you could ever do so don't :)

Jordan
  • 2,708
  • 4
  • 22
  • 35
3

Not practically. You can't just give the C# compiler a Java file, or vice versa.

If you're really determined though, you can use IKVM to expose Windows Forms to Java.

There's also J# but it's not being actively developed anymore.

parkovski
  • 1,503
  • 10
  • 13
1

No! It would not work. Java's GUI classes are different, so even if you renamed your .cs files to .java files and made slight modifications, the code would not work.

CodeBlue
  • 14,631
  • 33
  • 94
  • 132
1

No. It won't work. You can't compile Java and C# into a single executable package.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
1

No. The way Java and .NET interact with the GUI is totally different.

Jared Shaver
  • 1,339
  • 8
  • 12
1

I think you should learn how to make a GUI in Java if you are coding in Java. However if you want both of C# and Java to interoperate, then you need a new layer which acts like a bridge between a C# program runs on CLR and Java program runs on JVM. The following link has a good explanation about how to call Java routines directly from a C# program over runtime bridges:

http://www.devx.com/interop/Article/19945/1954

You need to bind something on GUI with an appropriate logic. Such as File>New menu selection might exist for creating a new file. Therefore this menu command needs to be bound to a logic. You can not run away without writing these logic, the event handlers or without defining some other functionalities inside of GUI classes. Strictly speaking, you always need to write a lot of code on presentation layer which consists of GUI classes. So that, your friend does also need to build up the presentation layer itself. Because a useless user interface is called a prototype not a program. And also do not forget about that runtime bridges significantly decrease the performance. Eventually, I suggest you to go and learn how to make GUI in Java.

ahmet
  • 646
  • 6
  • 14
  • You _can_ run Java on the CLR, but it's not normally done. See [IKVM.net](http://www.ikvm.net). – parkovski Feb 27 '12 at 01:29
  • I did not know it, thanks. Eventhough I have never used it, I guess it wont operate well. Still this might be an alternative solution for Scaream's question if he and his friend do a good teamwork :) – ahmet Feb 27 '12 at 01:52