我的问题是当我创建一个继承自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