java中如何设置按钮的透明度_如何保持JButtons的透明度(java)

我正在制作坦克游戏.在我的菜单中,我想将图片用作jbuttons,它们是部分透明的,当它们出现在屏幕上时,透明部分变为白色.

我尝试使用.setOpaque,但这不起作用.我想不出任何其他方法来摆脱白色部分.我一直在寻找堆栈溢出,但没有一种方法似乎有所帮助.谁有想法?

谢谢!

package menu;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

@SuppressWarnings("serial")

public class MenuPanel extends JPanel implements ActionListener

{

private Button playKnop, highScoreKnop, quitKnop, HTPKnop;

private JTextField naam;

private Image achtergrond;

private Tanks mainVenster;

public static String naam_input;

int x = 95, width = 200, height = 50;

public MenuPanel(Tanks mainVenster)

{

this.mainVenster = mainVenster;

this.setLayout(null);

playKnop = new Button("/buttons/PLAY.png", 350, this);

highScoreKnop = new Button("/buttons/HS.png", 460, this);

HTPKnop = new Button("/buttons/HTP.png", 515, this);

quitKnop = new Button("/buttons/QUIT.png", 570, this);

this.add(playKnop);

this.add(quitKnop);

this.add(HTPKnop);

this.add(highScoreKnop);

validate();

}

public class Button extends JButton

{

JButton button;

ImageIcon buttonImage;

String backgroundPath;

int y;

public Button(String backgroundPath, int y, MenuPanel menuPanel)

{

super();

this.backgroundPath = backgroundPath;

this.y = y;

buttonImage = new

ImageIcon(PlayPanel.class.getResource(backgroundPath));

this.setIcon(buttonImage);

this.setBounds(x, y, width, height);;

this.addActionListener(menuPanel);

}

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.drawImage(achtergrond, 0, 0, this.getWidth(), this.getHeight(),

this);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值