Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help again...
#1
In the video Making a game with Java part 3, i=I cant figure out why but its telling me "The field Component.y is not visible" here's my code:[code2=java]package levelEditor;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferStrategy;


public class LevelEditor
extends Canvas
implements KeyListener, Runnable, MouseListener{


private Object[][] grid = new Object[50][50];
private Graphics bufferGraphics = null;
private BufferStrategy bufferStrategy = null;
private boolean running;
private Thread thread;


public LevelEditor(Dimension size)
{
this.setPreferredSize(size);
this.addKeyListener(this);
this.thread = new Thread(this);
this.addMouseListener(this);
running = true;


}


public void paint(Graphics g)
{
if (bufferStrategy == null)
{
this.createBufferStrategy(2);
bufferStrategy = this.getBufferStrategy();
bufferGraphics = bufferStrategy.getDrawGraphics();
this.thread.start();
}
}

public void run() {
//THis is what runs when the level editor is running
while(running)
{
DoLogic();
Draw();
DrawBackBufferToScreen();
Thread.currentThread();
try
{
Thread.sleep(10);
}
catch(Exception e)
{
e.printStackTrace();
}
}

}

public void DoLogic()
{

}
public void Draw()
{
bufferGraphics = bufferStrategy.getDrawGraphics();
try
{
bufferGraphics.clearRect(0, 0, this.getSize().width, this.getSize().height);
for (int x = 0; x < grid.length; x++)
{
for (int y = 0; y < grid.length; y++);
{
Object o = grid[x][y]; //the problem line
if (o instanceof Block)
{
Block blockToDraw = (Block)o;
blockToDraw.draw(bufferGraphics);
}
}
}



}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
bufferGraphics.dispose();
}
}
public void DrawBackBufferToScreen()
{
bufferStrategy.show();
Toolkit.getDefaultToolkit().sync();
}

@Override
public void mouseClicked(MouseEvent e) {
int mouseX = e.getX();
int mouseY = e.getY();

mouseX = (mouseX / 25);
mouseY = (mouseY / 25);

grid [mouseX][mouseY] = new Block(mouseX * 25, mouseY * 25);
}




public void keyPressed(KeyEvent arg0) {


}
public void keyReleased(KeyEvent arg0) {


}
public void keyTyped(KeyEvent arg0) {


}





@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

}


@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}


@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub

}


@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}

}[/code2]
This was about 1/2 way thru the video.
the nasty red text said this "Exception in thread "Thread-1" java.lang.Error: Unresolved compilation problem:
The field Component.y is not visible

at levelEditor.LevelEditor.Draw(LevelEditor.java:84)
at levelEditor.LevelEditor.run(LevelEditor.java:55)
at java.lang.Thread.run(Unknown Source)
'


Messages In This Thread
Need help again... - by bigbubblewrap - 08-19-2012, 07:28 PM
Re: Need help again... - by Moldraxian - 08-20-2012, 07:30 AM
Re: Need help again... - by bigbubblewrap - 08-20-2012, 07:52 AM
Re: Need help again... - by Vinwarez - 08-21-2012, 05:15 AM
Re: Need help again... - by Aaron Rogers118 - 09-12-2012, 04:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)