当前位置: 技术问答>java相关
请教: 关于paint(Graphics g).
来源: 互联网 发布时间:2017-03-23
本文导语: 有 : //画布 class hyCanvas extends Canvas { public void paint(Graphics g) { int width = getSize().width; int height = getSize().height; g.setColor(Color.red); g.drawLine(0, 0, width, 0); g.drawLine(width, 0, width, height); g....
有 :
//画布
class hyCanvas extends Canvas {
public void paint(Graphics g)
{
int width = getSize().width;
int height = getSize().height;
g.setColor(Color.red);
g.drawLine(0, 0, width, 0);
g.drawLine(width, 0, width, height);
g.drawLine(0, height, width, height);
g.drawLine(0, 0, 0, height);
}
}
我想从一个按钮中调用画布对象的paint方法.实现画线功能该怎么办?
谢谢.
//画布
class hyCanvas extends Canvas {
public void paint(Graphics g)
{
int width = getSize().width;
int height = getSize().height;
g.setColor(Color.red);
g.drawLine(0, 0, width, 0);
g.drawLine(width, 0, width, height);
g.drawLine(0, height, width, height);
g.drawLine(0, 0, 0, height);
}
}
我想从一个按钮中调用画布对象的paint方法.实现画线功能该怎么办?
谢谢.
|
repaint()