Tito Tito - 24 days ago 12
Java Question

Error message in Java after extending JFrame

I'm having trouble with a snippet of code I am working on. I am extending JFrame in a class that contains my main method. I am sort of new to Java (learned it in university, have some practice with it, but still get stuck). I have a return type in my locate method that my IDE, eclipse NEON, is saying convert to COMPONENT. Here is my code:

import javax.swing.JFrame;

public class Board extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
boolean result;
int counter2;
int counter = 100000;
Point point = new Point(1,2,3);
int to_be_changed = 100000;
Point[] point2 = new Point[100000];
private int fortree = 0;


public static void main(String[] args)
{
Board bb = new Board();
int colChange = 1;


bb.add(1 ,0 ,1);

new work(bb);
}
public void add(int xco, int yco, int Colr)
{
point2[point2.length - counter] = new Point(xco, yco, Colr);
counter--;
counter2++;
}

public boolean Filled(int x1, int y1)
{
int i = 0;

do{
if (i > 100000){ i = 0; }
result = ((point2[i].getPoinx() == x1) && (point2[i].getPointy()== y1));
i++;
}while((result == false) && (i != counter2));


return result;
}

public Point locate(int x1, int y1)
{
Point backer = new Point(0,0,0);

for (int j = 0; ((j < point2.length) && (result == false) && (point2[j]) != null); j++ )
{
if ((point2[j].getPoinx() == x1) && (point2[j].getPointy() == y1))
{
backer = point2[j];
result = true;
}
}

return backer;
}

public void setfortree()
{
this.fortree++;
}

public int getfortree()
{
return this.fortree;
}

}

class work
{
work(Board y)
{
Intelligence p = new Intelligence();
System.out.println(p.tree(0, 0, y, 1, 1));
}
}


Can someone please tell me what is going on?
Thanks a lot

Answer

The JFrame class contains already a lot of methods. You are overriding an already existing method. One of those methods belongs to the superclass Container and has

  • as return-type a Component.
  • same list of parameters (two ints).

    @Deprecated public Component locate(int x, int y)

Eclipse knows about this and then reminds you that locate needs to return this Component. An easy test for this could be the renaming of your method.