class MyCanvas extends Canvas
{
Random r=new Random();
public void paint(Graphics g)
{
if(shape == "fillOval")
{
g.setColor(Color.red);
g.fillOval(r.nextInt(500),r.nextInt(250),50,50);
}
if(shape == "drawRect")
{
g.setColor(Color.CYAN);
g.drawRect(r.nextInt(500),r.nextInt(250),50,50);
}
}
上面paint方法中传入Graphics对象为什么没有显示创建?
Graphics类中的setColor方法是抽象方法为什么也可以直接调用呢?
请大师指点,谢谢!
{
Random r=new Random();
public void paint(Graphics g)
{
if(shape == "fillOval")
{
g.setColor(Color.red);
g.fillOval(r.nextInt(500),r.nextInt(250),50,50);
}
if(shape == "drawRect")
{
g.setColor(Color.CYAN);
g.drawRect(r.nextInt(500),r.nextInt(250),50,50);
}
}
上面paint方法中传入Graphics对象为什么没有显示创建?
Graphics类中的setColor方法是抽象方法为什么也可以直接调用呢?
请大师指点,谢谢!
这个又是怎么回事呢? 还是感谢大师指点。