0
import java.awt.*;
import java.util.*;
import javax.swing.*;

public class Mole extends JButton{
    private static final int MIN = 50;  
    private static final int MAX = 300;  
    static Random rand = new Random(); //declare Random statically so it does not have to be re-initiated for each use  
    private boolean up; //shows whether creature is alive or not 
    private int remaining_life; //shows how long the creature has currently been alive if applicable 
    private int zero_lives; //stores how long the creature will be alive for this life

    public Mole() {

        up = false;                  
                this.setBackground(Color.RED); 
                remaining_life = 0; 
    }

I'm able to use setBackground to change the color to red. But what If I wanted to use an image instead of a color?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Aizzle
  • 133
  • 1
  • 9
  • Have you tried `setIcon`? Have a look at [How to Use Buttons, Check Boxes, and Radio Buttons](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html) – MadProgrammer Nov 16 '15 at 00:52
  • Also have a look at [Reading/Loading an Image](http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html) – MadProgrammer Nov 16 '15 at 00:53

0 Answers0