I’m using a 2010 Mac with 1.6.0_37 Java, using DrJava to compile. The revalidate method does not compile, and I receive the following error:
2 errors found:
File: /Users/#########/compsci/Final/ConnectFourFrame.java [line: 123]
Error: /Users/#########/compsci/Final/ConnectFourFrame.java:123: cannot find symbol
symbol : method revalidate()
location: class ConnectFourFrame
This is the method giving rise to the error:
try
{
//display in window
updateTitleBar();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(currentFile));
colorGrid = (Color[][]) ois.readObject();
makeGrid();
for(int k = 0; k < 6; k++)
{
for(int l = 0; l < 7; l++)
{
if (colorGrid[k][l]==null)
{
grid[k][l] = new BlankTile(new Point(k, l));
}
else if (colorGrid[k][l].equals(Color.red))
{
grid[k][l] = new RedTile(new Point(k, l));
}
else if (colorGrid[k][l].equals(Color.black))
{
grid[k][l] = new BlackTile(new Point(k, l));
}
}
}
putNewGrid();
String currentColor = (String) ois.readObject();
ois.close();
ConnectFourFrame.this.repaint();
ConnectFourFrame.this.revalidate(); //This is the offending line
gp.revalidate();
gp.repaint();
}
And the outer class is ConnectFourFrame (extends JFrame and implements Runnable)
How can I resolve this issue?
Component.revalidate()is new in Java 7. Presumably you’re using 7 on Windows as opposed to 6 on Mac.If you need your code to work on Java 6 then you’ll have to do things differently. The JavaDoc for Component.revalidate says
Since a
JFrameis itself a validate root, you should just be able to replace therevalidatecall withinvalidate()followed byvalidate().