0

我正在尝试为 becker 机器人分配导入自定义图标。我使用 JFrame 创建了一个随机程序来显示图像,以确保文件路径等是正确的。但是现在我试图将 Becker 机器人的图标更改为它自己,而不是一个红色图标,我试图将其更改为 Minion 图标。我已经学会了使用图形 g 制作自己的定制设计机器人,然后将其分类为 SetIcon,但现在的挑战是使用我自己的外部 GIF 文件作为图标?我尝试和研究了很多天,不行。我在 mac 上使用 Eclipse。下面的代码工作正常,但我需要学习如何导入我自己的图标文件“gif”

这是给定制机器人的

import java.awt.*;
import becker.robots.icons.*;

public class Minion extends Icon
{
    public Minion()
    {
        // Constructor
        super();
    }
    public void paintIcon(Graphics g)
    {

        // Draw body
        g.setColor(Color.YELLOW);
        g.fillOval(30, 30, 40, 40);
        // Draw shoulders
        g.setColor(Color.BLUE);
        g.fillRect(20, 45, 10, 10);
        g.fillRect(70, 45, 10, 10);
        // Draw arms
        g.setColor(Color.PINK);
        g.fillOval(20, 20, 10, 35);
        g.fillOval(70, 20, 10, 35);
        // Draw eyes
        g.setColor(Color.BLACK);
        g.fillOval(35, 40, 10, 10);
        g.fillOval(55, 40, 10, 10);
    }
}

这是我将上面绘制的机器人转换为图标文件的地方

package Pacman;
import becker.robots.*;
import java.awt.*;

public class SetIcon extends RobotSE
{
    public SetIcon(City aCity, int str, int ave, Direction dir)
    {
        super(aCity, str, ave, dir);
        setIcon(new Minion());
    }
}

这是创建游戏的主要代码

package Pacman;
import becker.robots.*;
public class Pacman  {
public static void main(String[] args) {
    {
        new Pacman();
    }


    City Mania = new City();
    //String Robot = "icon.gif";

    SetIcon minion = new SetIcon(Mania, 4, 3, Direction.NORTH);
4

0 回答 0