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一搜一大堆,这是其中一个,楼主试试,不行的话自己搜搜吧.