Java |
import java.awt.event.ActionListener;
public class Form1 extends java.awt.Frame implements ActionListener {
java.awt.Button button1 = new Button();
public void actionPerformed(ActionEvent ae) {
System.out.println("button1 was clicked!");
}
button1.addActionListener(this);
...
}
|
|
C# |
public delegate void EventHandler(object sender, System.EventArgs e);
public class Button
{
private EventHandler handler;
public event EventHandler Click {
add { handler += value; }
remove { handler -= value; }
}
}
public class Form1
{
public Form1() {
// Add Button1_Click as an event handler for Button1's Click event
Button1.Click += new EventHandler(Button1_Click);
}
Button Button1 = new Button();
void Button1_Click(object sender, EventArgs e) {
Console.WriteLine("Button1 was clicked!");
}
public void Disconnect() {
Button1.Click -= new EventHandler(Button1_Click);
}
}
|
|