0

I tried to put an image on a JButton and it's messed up:

http://imgur.com/ecBOt


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

3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by NormR1
0

Can you explain what "messed up" means? What were we supposed to see in the posted image?

0

Can you explain what "messed up" means? What were we supposed to see in the posted image?

the Jbuttons edges are in there, it's not just a clickable image

0

it's not just a clickable image

What is supposed to happen when you click on the button?
You need to add an actionListener if you want the program to react.

0

What is supposed to happen when you click on the button?
You need to add an actionListener if you want the program to react.

I understand that, I mean that the button looks weird

0

Change the image to something that is not weird looking.

Can you show a non-weird image vs a weird image?

Edited by NormR1: n/a

0

Change the image to something that is not weird looking.

Can you show a non-weird image vs a weird image?

the image looks fine, I mean it doesn't look like the menu buttons in minecraft or something

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.