将setBackground(Color.Red)更改为图像

时间:2015-11-16 00:50:46

标签: java swing jbutton

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; 
    }

我可以使用setBackground将颜色更改为红色。但是,如果我想使用图像而不是颜色呢?

0 个答案:

没有答案