1.使得图片透明
(1)PS里调整透明度,保存为png格式
(2)Graphics2D g2d=(Graphics2D)g;
g2d.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.75f));
2.绘制自己的容器,以button为例
自己定义一个类myButton继承JButton
构造函数
public MyButton(String title,Image IMAGE_BTN)
{
super(title);
//用来绘制按钮的图片
this.IMAGE_BTN = IMAGE_BTN;
//取消button边框
setBorder(null);
}
重写paintComponent方法
public void paintComponent(Graphics g)
{
g.drawImage(this.IMAGE_BTN, 0, 0,this.getWidth(), this.getHeight(), 0,0,IMAGE_BTN.getWidth(null) ,IMAGE_BTN.getHeight(null),null);
}
然后new的时候把目标图片和位置放进去就好,效果如下
3.用按钮使新的Frame关闭,调用this.dispose();
要新的Frame点击右上角关闭时不关闭整个程序,this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);