473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Java to C#....

Hi,
How can I translate this method in C# ?
public void actionPerformed (ActionEvent event)
{
if even.getSource() == mybtn
{
sayHello();
}
}

Thanks in advance.
Nov 16 '05 #1
4 1534
In article <#G**************@TK2MSFTNGP09.phx.gbl>, genc_ ymeri at hotmail dot com wrote:
Hi,
How can I translate this method in C# ?
public void actionPerformed (ActionEvent event)
{
if even.getSource() == mybtn
{
sayHello();
}
}

Thanks in advance.


This looks like a Java listener (I haven't done Java is several years
now, so I could be wrong :)...

Anyway, that would be a click evnet in C#....

So, you would have something like:

mybtn.Click += new EventHandler (actionPerformed);

private void actionPerformed (object sender, System.EventArgs e)
{
sayHello ();
}

Of course, you can hook this to more then one button, so you might have
something like:

private void actionPerformed (object sender, System.EventArgs e)
{
if (sender == mybtn)
{
sayHello ();
}
}

HTH
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 13 Days, 20 Hours, 16 Minutes, 22 Seconds
Nov 16 '05 #2
Well, probably I missed your point but to me it seems like it's not quite
the same though. In other words, is there anyaway in C# I can retrieve all
the events that fired from any possible control within a form and
discreminate them from the source without assigning the handler to the
controls (the source) ?????

Thanks.


"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
In article <#G**************@TK2MSFTNGP09.phx.gbl>, genc_ ymeri at hotmail
dot com wrote:
Hi,
How can I translate this method in C# ?
public void actionPerformed (ActionEvent event)
{
if even.getSource() == mybtn
{
sayHello();
}
}

Thanks in advance.


This looks like a Java listener (I haven't done Java is several years
now, so I could be wrong :)...

Anyway, that would be a click evnet in C#....

So, you would have something like:

mybtn.Click += new EventHandler (actionPerformed);

private void actionPerformed (object sender, System.EventArgs e)
{
sayHello ();
}

Of course, you can hook this to more then one button, so you might have
something like:

private void actionPerformed (object sender, System.EventArgs e)
{
if (sender == mybtn)
{
sayHello ();
}
}

HTH
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 13 Days, 20 Hours, 16 Minutes, 22 Seconds

Nov 16 '05 #3
genc_ ymeri at hotmail dot com <ge********@hotmail.com> wrote:
Well, probably I missed your point but to me it seems like it's not quite
the same though. In other words, is there anyaway in C# I can retrieve all
the events that fired from any possible control within a form and
discreminate them from the source without assigning the handler to the
controls (the source) ?????


No, you can't do that in C#. It's not a terribly nice way of writing UI
code though - and it's one which even in Java isn't the normal way of
doing things any more.

In C#, you subscribe to individual events. Several events can have the
same handler, and you can tell which control fired the event using the
sender parameter, but you can't (easily, anyway) say "give me all
events for all controls on this page".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Greatly appreciated !
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
genc_ ymeri at hotmail dot com <ge********@hotmail.com> wrote:
Well, probably I missed your point but to me it seems like it's not quite
the same though. In other words, is there anyaway in C# I can retrieve
all
the events that fired from any possible control within a form and
discreminate them from the source without assigning the handler to the
controls (the source) ?????


No, you can't do that in C#. It's not a terribly nice way of writing UI
code though - and it's one which even in Java isn't the normal way of
doing things any more.

In C#, you subscribe to individual events. Several events can have the
same handler, and you can tell which control fired the event using the
sender parameter, but you can't (easily, anyway) say "give me all
events for all controls on this page".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
1
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.