画笔

使用方式:

在继承JPanel的类里面重写paintComponet(Graphics g)方法

protected void paintComponent(Graghics g){
    //清屏
    super.paintComponent(g);
    //ImageIcon对象.paintIcon(面板对象,画笔,x坐标,y坐标)
    header.paintIcon(this,g,1,2);
    //将从(1,2)位置开始500*400大小的区域填充矩形
    g.fillRect(1,2,500,400);
}

注意:

上面代码中的header是一个ImageIcon的对象,这个对象不要写在画板存在的类中,可能会出错,我就出错了,放在一个新的类(Data)中保存和取用

posted @ 2023-04-05 11:14  Geek李  阅读(71)  评论(0)    收藏  举报