主题:MouseListener用错了?
各位这个程序在我这里怎么说没有覆盖另一个方法呀?我这个可是用了适配器的呀!还有我的那个Graphics g用的对吗?能画出圆来吗?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RandomClick extends JApplet implements MouseListener
{Color c;Graphics g;
public void init()
{addMouseListener(new MouseAdapter()
{public void mouseTyped(MouseEvent e)
{int x=e.getX();int y=e.getY();
c=new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
g.setColor(c);
g.fillOval(x-10,y-10,10,10);
}
});
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RandomClick extends JApplet implements MouseListener
{Color c;Graphics g;
public void init()
{addMouseListener(new MouseAdapter()
{public void mouseTyped(MouseEvent e)
{int x=e.getX();int y=e.getY();
c=new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
g.setColor(c);
g.fillOval(x-10,y-10,10,10);
}
});
}
}