一个接口有多少种方法是理想的数量?你怎么知道一个接口从一个实现中有多少方法?那么 Mouselistener 接口会有 5 个方法吗?
// ToggleButton Listener Class:
class ToggleButton implements MouseListener {
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mouseClicked(MouseEvent e) {
// e.getButton() returns 0, 1, 2, or 3, where 1 is the
// left mouse button and 3 is the right mouse button:
mousebutton = e.getButton();
// Identify which JButton was clicked on by getting the
// source of the event e; Book, p. 484 (Event and Event
// Source);
// e.getSource() returns an object of the Object
// superclass, and that object has to be cast to a
// JButton with (JButton):
JButton B = (JButton)e.getSource();
nextSymbol( B );
}
} // end ToggleButton class