i'm making a tank game. in my menu i want to use pictures as jbuttons, they are partly transparent and when they appear on screen the transparent parts become white.
i tried using
.setOpaque
but this doesn't work. i can't think of any other method to get rid of the white parts. i've been looking all over stack overflow but none of the methods seem to help. anyone who has an idea?
Thanks!
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);
}
}