Sqnyy

Hi all..

I want to convert a java program to C# project.
I used JLCA but the new C# project gives me 57 errors..

Like :

Error 1 The type or namespace name 'EventListener' could not be found (are you missing a using directive or an assembly reference )
Error 2 The type or namespace name 'TreeCellRenderer' could not be found (are you missing a using directive or an assembly reference )
.
.
.
.

etc..

How can I implement java classes to .Net. Like EventListener.
I need an JLCA examples too..
I developed a lot of C# project but I have never had a problem like this..
I love C# and I want to go on with Java..
Any help will be appreciated, thanks in advance.

Soner Altin





Re: Visual C# Language Java to C#

Marcelo Guerra - MSFT

Can you post a small sample code of places where you are getting errors . Like what's the code that gives error 1



Re: Visual C# Language Java to C#

Kea

C# has intrinsic support for events as opposed to Java, so using the EventListener interface is unecessarily complicated, you'd rather have to redesign your code to take advantage of events instead.




Re: Visual C# Language Java to C#

Sqnyy

Sure:

public class FloatDocument:PlainDocument
gives error
Error 1 The type or namespace name 'PlainDocument' could not be found (are you missing a using directive or an assembly reference )

or

public interface MouseHandleListener:MouseListener, MouseMotionListener
gives error
Error 2 The type or namespace name 'MouseListener' could not be found (are you missing a using directive or an assembly reference )







Re: Visual C# Language Java to C#

Sqnyy

Ok. I understand. You suggest me to design the forms again and copy the algorithms from Java to C#. Am I right So I don't need to use Events.

Thanks for the answer.
Soner





Re: Visual C# Language Java to C#

Kea

You should still continue to use the concept of events, but you wouldn't bind them using interfaces as in Java, rather in a way that is provided by the compiler and run-time. An event type in C# is declared in the following manner (you wouldn't get far without using events in GUIs):

public delegate void SampleEventHandler(object sender);

And an event declaration:

public SampleEventHandler SampleEvent;

If you look at the delegate declaration, it's void, which is a requirement for events, but not delegates (an event raiser shouldn't have to handle possibly tenfolds of return values, that makes no sense). In .NET, it is customary to have the first parameter in an event method to be the sender object, IF it applies, and it usually does in GUIs. It is also customary to suffix the template delegate for the event with "Handler".

You subscribe to the event somewhere with either of the two following statements, in a method body:


SampleEvent += new SampleEventHandler(SubscriberFunction);
SampleEvent += SubscriberFunction;

I don't know what's the difference, except for the explicity of the first one. Both subscriber function and event must be fully qualified. You unsubscribe with -=, but for GUIs that's not necessary, unless you want to alter the behaviour of GUI responses. The subscribers are called in sequence, in the order they were added ("addhandler"), on the calling thread. To raise the event:

SampleEvent();

So, for your app, I strongly encourage you to redesign the
forms, using a visual form editor (don't code it by hand), like the one provided in Visual Studio, this gives you a great starting point and automaticlly binds events for you. You'll discover what partial classes can do, and do look at the code that GUI designer generates for you.
As for "
copy the algorithms from Java to C#" that depends, of course, on what strategies the algorithms use, i.e. events. However, doing those separately (GUI and algorithms) you are decoupling your GUI code from your program logic, which serves to provide you with a more robust end result =).
Also remember to prefix your interfaces with 'I', it makes them pretty easy to distinguish in code.