here is my code im trying to put a image but every time, i have an error in the getimage() part. Can you please help? Thank you. I know it's a weird project. Or can you tell me how to write a code for drawing a circle and dividing them to pieces. Every piece is a different color then i put them in a linked list and ask the user which color they hate and then i remove it. I do the same thing every time until i only have one color left. I don't know how to do that so i did it a different way so can you help me:
import java.util.*;
import java.util.Scanner;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
public class ExtraCredit extends Applet
{
//graphic
public void paintOr(Graphics g)
{
Image img;
MediaTracker tr;
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "Or.png");
tr.addImage(img,0);
g.drawImage(img, 0, 0, this);
}
public void paintRed(Graphics g1)
{
Image img;
MediaTracker tr;
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "red.png");
tr.addImage(img,0);
g1.drawImage(img, 0, 0, this);
}
public void paintR(Graphics g2)
{
Image img;
MediaTracker tr;
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "R.png");
tr.addImage(img,0);
g2.drawImage(img, 0, 0, this);
}
public void paintRBrown(Graphics g3)
{
Image img;
MediaTracker tr;
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "rbrown.png");
tr.addImage(img,0);
g3.drawImage(img, 0, 0, this);
}
public void paintBr(Graphics g4)
{
Image img;
MediaTracker tr;
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "Br.png");
tr.addImage(img,0);
g4.drawImage(img, 0, 0, this);
}
public void paintBrBlue(Graphics g5)
{
Image img;
MediaTracker tr;
tr = new MediaTracker(this);
img = getImage(getCodeBase(), "brblue.png");
tr.addImage(img,0);
g5.drawImage(img, 0, 0, this);
}
//----
public static void main(String[] args)
{
ExtraCredit ex = new ExtraCredit();
String cF;
int i=0;
LinkedList<String> c = new LinkedList<String>();
c.add("red");
c.add("brown");
c.add("blue");
c.add("green");
Scanner scan = new Scanner (System.in);
//first loop
while(i!=4)
{
i++;
System.out.println ("You have a list of color:brown, blue, green, red");
Graphics g = ex.getGraphics();
ex.paintOr(g);
System.out.println ("which color you most hate:");
String color1 = scan.nextLine();
//cF=c.getFirst();
if(color1 == c.getFirst())
{
Graphics g1 = ex.getGraphics();
ex.paintRed(g1);
}
c.remove(color1);
}
i=0;
// second loop
while(i!=3)
{
i++;
System.out.println ("You have a list of color:"+ c);
Graphics g2 =ex.getGraphics();
ex.paintR(g2);
System.out.println ("which color you most hate:");
String color2 = scan.nextLine();
if(color2 == c.getFirst())
{
Graphics g3 = ex.getGraphics();
ex.paintRBrown(g3);
}
c.remove(color2);
}
i=0;
//third loop
while(i!=2)
{
i++;
System.out.println ("You have a list of color:"+ c);
Graphics g4=ex.getGraphics();
ex.paintBr(g4);
System.out.println ("which color you most hate:");
String color3 = scan.nextLine();
cF=c.getFirst();
if(color3 == c.getFirst())
{
System.out.println ("The color you like:" + c);
Graphics g5 = ex.getGraphics();
ex.paintBrBlue(g5);
}
c.remove(color3);
}
}
}