首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请高手指教,ShapePanel 怎么调用,在哪个包中?

2011-12-30 
请高手指教,ShapePanel 如何调用,在哪个包中??ShapePanel类在哪个包中[解决办法]据我所知,API中没有这个类

请高手指教,ShapePanel 如何调用,在哪个包中??
ShapePanel类在哪个包中

[解决办法]
据我所知,API中没有这个类,自定义的吧。
[解决办法]
class ShapePanel extends JPanel
{
public ShapePanel()
{
setPreferredSize(new Dimension(300, 300));
addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent evt)
{
begin.x = evt.getX();
begin.y = evt.getY();

end.x = (int)((Math.random() * (width + 1)));
end.y = (int)((Math.random() * (height + 1)));
Insets border = getInsets();
width = getWidth() - (border.left + border.right);
height = getHeight() - (border.top + border.bottom);

if (begin.x > end.x)
{
minx = end.x;
rwidth = begin.x - minx;
}
else
{
minx = begin.x;
rwidth = end.x - minx;
}

if (begin.y > end.y)
{
miny = end.y;
rheight = begin.y - miny;
}
else
{
miny = begin.y;
rheight = end.y - miny;
}
repaint();
}
});

addMouseMotionListener(new MouseMotionAdapter()
{
public void mousePressed(MouseEvent evt)
{
begin.x = evt.getX();
begin.y = evt.getY();
}
});

addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDraqqed(MouseEvent evt)
{
end.x = evt.getX();
end.y = evt.getY();
repaint();
}

});
}
public void paintComponent(Graphics g)
{
g.drawRect(minx, miny, rwidth, rheight);

}
}
//baidu一搜一大堆,这是其中一个,楼主试试,不行的话自己搜搜吧.

热点排行