这个程序加上this就出错,这是什么原因?
import java.awt.*;import java.awt.event.*;
public class DrawLine extends Frame
{ private int orgx,orgy,endx,endy;
public static void main(String []args)
{
DrawLine d1=new DrawLine();
d1.init();
}
public void paint(Graphics g)
{
g.drawLine(orgx,orgy,endx,endy);
}
public void init()
{
this.setSize(300,300);
this.setVisible(true);
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
orgx=e.getX();
orgy=e.getY();
}
public void mouseReleased(MouseEvent e)
{
endx=e.getX();
endy=e.getY();
Graphics g=this.getGraphics();//这里,去掉this就能编译通过,加上就错
g.setColor(Color.red);
g.setFont(new Font("隶书",Font.ITALIC|Font.BOLD,30));
g.drawString(new String(orgx+","+orgy),orgx,orgy);
g.drawString(new String(e.getX()+","+e.getY()),e.getX(),e.getY());
g.drawLine(orgx,orgy,e.getX(),e.getY());
}
});
}
}
错误信息:
DrawLine.java:31: 找不到符号
符号: 方法 getGraphics()
Graphics g=this.getGraphics();
^
1 错误
我看不出错在哪里,谁知道问题出在哪儿?
谢谢!!
[此贴子已经被作者于2006-3-23 8:22:46编辑过]