我的問題是當我創建一個繼承自JPanel的類時,爲什麼不使用super.addMouseListener()來添加一個偵聽器?我認爲這種方法是在JPanel的超類中。 這裏是代碼:爲什麼addMouseListener方法不需要超級?
private class DrawPanel extends JPanel
{
private int prefwid, prefht;
// Initialize the DrawPanel by creating a new ArrayList for the images
// and creating a MouseListener to respond to clicks in the panel.
public DrawPanel(int wid, int ht)
{
prefwid = wid;
prefht = ht;
chunks = new ArrayList<Mosaic>();
// Add MouseListener to this JPanel to respond to the user
// pressing the mouse. In your assignment you will also need a
// MouseMotionListener to respond to the user dragging the mouse.
addMouseListener(new MListen());
}
因爲它是遺傳的 – trooper