1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// A sample class to test the debugger.
// $Id: overload.java 1113 2004-01-25 22:25:32Z nfiedler $
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class overload implements ActionListener {
private JFrame mainWin;
private JButton button1;
private JButton button2;
public overload() {
mainWin = new JFrame("b tester");
Container pane = mainWin.getContentPane();
pane.setLayout(new BorderLayout());
button1 = new JButton("Push me");
pane.add(button1, "North");
button1.addActionListener(this);
button2 = new JButton("No, push me instead");
pane.add(button2, "South");
button2.addActionListener(this);
mainWin.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
mainWin.setSize(300, 100);
mainWin.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Object button = e.getSource();
if (button == button1) {
overloadedMethod();
} else {
overloadedMethod("Second button was pushed");
}
}
public void overloadedMethod() {
System.out.println("First button was pushed.");
}
public void overloadedMethod(String msg) {
System.out.println(msg);
}
public static void main(String[] args) {
new overload();
}
}
|