日期:2014-05-20  浏览次数:20678 次

在已知图片上添加图片为什么老是被覆盖

如图所示,需求是选择一张图片打开,然后可以根据按钮显示不同方向的图片。
现在我的问题是,图中有只兔子,如何把兔子添加到背景图片上?
我是这么写的,但是我发现兔子被背景图片覆盖了,显示不出来。
   //添加兔子
   public void setIcon(MainFrame frame)
   {
           //从兔子图片的路径得到兔子图片对象
           ImageIcon icon1 = new ImageIcon("/afs/user/Desktop/location/Rabbit.JPG");
           image1 = icon1.getImage();
           //得到背景图像的画笔,背景图像画在主frame的label上
           Graphics2D g=(Graphics2D)frame.getLabel().getGraphics();
           //画兔子
           g.drawImage(image1, 400, 400, frame.getLabel());
       
   }

求指教~
------最佳解决方案--------------------
谁告诉你要在JLabel上画的啊,你打他啊1
JLabel iconLabel = new JLabel();
ImageIcon icon1 = new ImageIcon("/afs/user/Desktop/location/Rabbit.JPG");
iconLabel.setIcon(icon1)
frame.getContentPanel().add(iconLabel, BorderLayout.center);


------其他解决方案--------------------
引用:
谁告诉你要在JLabel上画的啊,你打他啊1
Java code?1234JLabel iconLabel = new JLabel();ImageIcon icon1 = new ImageIcon("/afs/user/Desktop/location/Rabbit.JPG");iconLabel.setIcon(icon1)frame.getContentPane……

知道了,谢谢~
------其他解决方案--------------------
用jLayeredPane做容易的多,参考http://www.oschina.net/code/snippet_54100_1239