I tried to put an image on a JButton and it's messed up:
code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Polluted extends JFrame implements ActionListener {
ImageIcon bg = new ImageIcon("bg.png");
Image bgImage = bg.getImage();
public static void main(String[] args) {
new Polluted();
}
public Polluted()
{
JPanel panel = new JPanel();
Image playImage = getToolkit().createImage("play.png");
ImageIcon playButton = new ImageIcon(playImage);
this.setSize(800, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Polluted");
this.setResizable(false);
this.setLayout(new GridBagLayout());
JButton play = new JButton(playButton);
this.add(play);
this.setVisible(true);
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Toolkit bgKit = Toolkit.getDefaultToolkit();
bgImage = bgKit.getImage("bg.png");
g.drawImage(bgImage, 0, 0, this);
}
public void actionPerformed(ActionEvent donotuse) {
}
}
also if you could help me make a background image work that would be cool :3
Thanks in advance, upanotch