0

Im trying to import a custom icon for a becker robot assignment. I created a random program using the JFrame to display the image to make sure the file path and so on was correct it worked. But now Im trying to change the Icon for Becker robot it self rather then a red icon im trying to change it to an Minion icon. I've learned to make my own custom designed robot using graphics g then classyfying it to SetIcon but now the challenge comes to using my own external GIF file as an icon? ive tried and researched alot for couple days no go. Im using Eclipse on mac. The below code works fine but I need to learn how to import my own Icon file "gif"

this is for the custom robot

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

this is where i convert the above drawn robot to Icon file

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

this is the main code where the game would be created

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);
Holger
  • 285,553
  • 42
  • 434
  • 765

0 Answers0