C# analog's of Java classes

T

TomC

Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?
 
G

Guest

Import your .java class files into Visual Studio, which will use the JLCA to
translate them to J#.
Now they are .NET classes.
Peter
 
T

TomC

I'm not trying to convert an existing Java application. I'm trying to
learn C#, and I have an idea of something that I'd like to attempt as a
learning project.

I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.
 
L

Lucian Wischik

TomC said:
I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.

My impression is that Java likes to use inheritance a heck of a lot,
and .net tends to use it less. Quite commonly you never even inherit
any classes yourself -- you use events instead.

(although if you were writing a component yourself then you do end up
writing more inheritance yourself).

So, it's hard to answer in isolation what is the equivalent of a java
panel. Instead you should describe the problem you're trying to solve,
(and maybe describe how you architected it in java), and then see what
people answer for most typical way to do it in .net.
 
T

TomC

Lucian said:
My impression is that Java likes to use inheritance a heck of a lot,
and .net tends to use it less. Quite commonly you never even inherit
any classes yourself -- you use events instead.
(although if you were writing a component yourself then you do end up
writing more inheritance yourself).

In this case, I don't see any way to get around using inheritance.
What I want to do is create a custom visual display, so I need to
customize some sort of object that can be displayed visually.
So, it's hard to answer in isolation what is the equivalent of a java
panel. Instead you should describe the problem you're trying to solve,
(and maybe describe how you architected it in java), and then see what
people answer for most typical way to do it in .net.

OK. Here is an idea that is similar to what I want to do, but more
familiar than my project would be.

Imagine that I was creating a virtual checkerboard class. What I'm
trying to do would be similar to creating a class that represents an
individual square on the checkerboard. It needs to have the the
ability to draw on itself, so I can program it to draw things that look
like checkers, chess pieces, and possibly other images within its
border. By tiling them together to create the image of a checkerboard
with the ability to render the correct game pieces.

The logic for the game would be elsewhere. My goal here is to create
the display. In Java, I'd subclass the Panel class, or possibly the
Component class to accomplish this. Now, surely, there is something
similar in C#.
 
L

Lucian Wischik

TomC said:
In this case, I don't see any way to get around using inheritance.
What I want to do is create a custom visual display, so I need to
customize some sort of object that can be displayed visually.

Right, there are two types of customizations: (1) by the creator of
the application, who normally customizes by adding events instead of
by inheriting; (2) by the middleware/componentware author who creates
new components through inheritance.

Wearing your application-creator hat, you'd plonk down a PictureBox on
your form, one for each square. You'd probably just set its "Image"
property to the image (draughtspiece, chesspiece, blank...). Or you
could override its OnPaint event. That's to say, OnPaint is a list of
method+instance-pointers, and you will make it point to the
ChesspiecePaint method of your MyForm, and your MyForm will contain
the logic for painting it. Maybe you'd use its "tag" property to store
its coordinates or something like that.

Wearing your componentware-author's hate, you'd inherit from
PictureBox and add any properties that you see fit.

It needs to have the the ability to draw on itself

So the .net/winforms philosophy is that often it's the
application/form that has the ability to draw the unusual controls it
uses, and which has the ability to respond to their clicks. Instead of
the java philosophy where it's normally the control itself that knows
how to paint itself.
 
G

Guest

What I was proposing was that after you get your Java classes compiled as
..NET assemblies, it is easy to use tools like Roeder's Reflector to decompile
them into C# source code. This makes the task of comparing how one would
perform the analogous coding in .NET very easy.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
T

TomC

Lucian said:
Right, there are two types of customizations: (1) by the creator of
the application, who normally customizes by adding events instead of
by inheriting; (2) by the middleware/componentware author who creates
new components through inheritance.

Wearing your application-creator hat, you'd plonk down a PictureBox on
your form, one for each square. You'd probably just set its "Image"
property to the image (draughtspiece, chesspiece, blank...). Or you
could override its OnPaint event. That's to say, OnPaint is a list of
method+instance-pointers, and you will make it point to the
ChesspiecePaint method of your MyForm, and your MyForm will contain
the logic for painting it. Maybe you'd use its "tag" property to store
its coordinates or something like that.

Wearing your componentware-author's hate, you'd inherit from
PictureBox and add any properties that you see fit.



So the .net/winforms philosophy is that often it's the
application/form that has the ability to draw the unusual controls it
uses, and which has the ability to respond to their clicks. Instead of
the java philosophy where it's normally the control itself that knows
how to paint itself.
Thank you!

This is the type of information that I need. What I am planning is
probably more in the middleware category. I want to create a class
that I can reuse in a variety of ways. In one application it might be
a square on a chessboard, in another it might be a square in a in a
Battleship clone, and in a third it might be drawing a giant
mathematical symbol.

The events would be added later.

I can start by looking at the documentation for the PictureBox class.
It is possible that I can even go further up the inheritance chain
since I would not be drawing .gif's or .bmp's but shapes like circles,
squares and other polygons. But at least now I know where to start
looking.

Now, if I could just find site that maps the various Java classes to
their analogous C# classes I could find this stuff myself.
 
T

TomC

Oh. I'm not familiar with Roeder's Reflector, but I can see where that
could help. Of course, that would mean writing the whole thing in Java
first, and then rewriting it in C#. I really do appreciate the reply,
but it still seems to be an inefficient use of time. Would it make
sense to create HelloWorld in Java, convert it .NET, and then decompile
it just to find out that the equivalent of System.out.println("Hello,
world!"); in C# is System.Console.WriteLine("Hello, world!");?

Again, I really DO appreciate that you've taken the time to reply.
Maybe I'm missing something.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

TomC said:
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?

I am not a GUI guy myself, but:

http://www.thescripts.com/forum/thread237279.html

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top