做了一个类似QQ表情框,有点问题,请大家看下。。

tx183584 2010-07-26 06:26:11
想在每个表情画一个框,但是有些框不会出现。。
表情包在这里下载:http://u.115.com/file/t95377871e
face.rar
public class   ExpressionDialog extends JDialog{

JLabel label;
int x,y;
final private int WIDTH=30,HEIGHT=30;
public ExpressionDialog(JFrame frame,int xx,int yy)
{

super(frame);

setUndecorated(true);
setLayout(new GridLayout(8,15));
setBounds(xx, yy, 451, 242);
setBackground(Color.blue);
for(x=0;x<120;x++)
{
label=new JLabel(new ImageIcon("image/face/"+x+".gif"));
// System.out.println("image/face/"+x+".gif");

add(label);

}
addWindowListener(new winAction());
addMouseListener(new Action());
}

public void paint(Graphics g)
{
super.paintComponents(g);
g.setColor(new Color(0,0,0));
for(x=0;x<=450;x=x+WIDTH)
for(y=0;y<=230;y=y+HEIGHT)
g.drawRect(x, y, x+HEIGHT, y+WIDTH);

}

class Action extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
x=e.getX()/30;
y=e.getY()/30;
//repaint();
JFrame frame = (JFrame) ExpressionDialog.this.getOwner();
}

}
class winAction extends WindowAdapter
{

public void windowDeactivated(WindowEvent e) { //表情框失去焦点时调用
ExpressionDialog.this.setVisible(false);
// ExpressionDialog.this.setVisible(false);
}

}
}
...全文
180 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huntor 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tx183584 的回复:]

引用 3 楼 huntor 的回复:

也许是被挡住了。

你的表情使用JLabel显示的。想在每个上面加框。只需调用JLabel的setBorder方法即可。

但是每个表情图片大小都是相同的。。。。
[/Quote]

图片的大小 != JLabel的大小
tx183584 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 huntor 的回复:]

也许是被挡住了。

你的表情使用JLabel显示的。想在每个上面加框。只需调用JLabel的setBorder方法即可。
[/Quote]
但是每个表情图片大小都是相同的。。。。
tx183584 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 huntor 的回复:]

Java code
label=new JLabel(new ImageIcon("image/face/"+x+".gif"));

label.setBorder(BorderFactory.createLineBorder(Color.BLUE,2));


这样如何
[/Quote]
但是为什么。我画的线,有些地方会显示不出来,我的图片的大小是一样的
huntor 2010-07-27
  • 打赏
  • 举报
回复
也许是被挡住了。

你的表情使用JLabel显示的。想在每个上面加框。只需调用JLabel的setBorder方法即可。
huntor 2010-07-26
  • 打赏
  • 举报
回复
label=new JLabel(new ImageIcon("image/face/"+x+".gif"));

label.setBorder(BorderFactory.createLineBorder(Color.BLUE,2));


这样如何

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧