VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1122|回复: 5

关于JPanel的问题?

[复制链接]

1

主题

3

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
发表于 2020-1-4 08:30:01 | 显示全部楼层 |阅读模式
我在JPanel上用drawLine函数绘制了一系列线条,现在我想清除这些线条,请问怎么清除啊?
回复

使用道具 举报

0

主题

39

帖子

23.00

积分

新手上路

Rank: 1

积分
23.00
发表于 2020-1-4 11:51:01 | 显示全部楼层
用背景色再画一条线上去
回复

使用道具 举报

1

主题

3

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
 楼主| 发表于 2020-1-4 13:27:01 | 显示全部楼层
可是,如果我已经画了很多线了啊,总不能记录下相同的路径,在进行逆序操作吧?
回复

使用道具 举报

0

主题

3

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-1-4 23:12:02 | 显示全部楼层
clearRect()可以清除全部的东东.
回复

使用道具 举报

1

主题

3

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
 楼主| 发表于 2020-1-5 15:24:01 | 显示全部楼层
怎么调用啊?在什么地方调用啊?
回复

使用道具 举报

1

主题

20

帖子

15.00

积分

新手上路

Rank: 1

积分
15.00
发表于 2020-1-5 16:57:01 | 显示全部楼层
clearRect
public abstract void clearRect(int x,
                               int y,
                               int width,
                               int height)
Clears the specified rectangle by filling it with the background color of the current drawing surface. This operation does not use the current paint mode.
Beginning with Java 1.1, the background color of offscreen images may be system dependent. Applications should use setColor followed by fillRect to ensure that an offscreen image is cleared to a specific color.


Parameters:
x - the x coordinate of the rectangle to clear.
y - the y coordinate of the rectangle to clear.
width - the width of the rectangle to clear.
height - the height of the rectangle to clear.





for example:
g.clearRect(0, 0, 400, 400);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表