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);