BP Forums
Need help again... - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19)
+---- Thread: Need help again... (/showthread.php?tid=609)



Need help again... - bigbubblewrap - 08-19-2012

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)
'


Re: Need help again... - brandonio21 - 08-19-2012

Ah, so here's the problem. A few lines above your error line, you have this line:
[code2=java]for (int y = 0; y < grid.length; y++);[/code2]

You inserted a semi-colon (Wink at the end of your for opening, which effectively destroys the "y" variable, hence your error. Simply remove the semi-colon and you should be good!


Re: Need help again... - Moldraxian - 08-20-2012

Wow. Java code looks so much like C++ code it's not even funny.


Re: Need help again... - bigbubblewrap - 08-20-2012

...that's ridiculous, seriously that just sucks <!-- sConfusedhock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt="Confusedhock:" title="Shocked" /><!-- sConfusedhock: --> <!-- sSad --><img src="{SMILIES_PATH}/icon_e_sad.gif" alt="Sad" title="Sad" /><!-- sSad --> . But thanks a lot! <!-- sBig Grin --><img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt="Big Grin" title="Very Happy" /><!-- sBig Grin -->


Re: Need help again... - Vinwarez - 08-21-2012

Moldraxian Wrote:Wow. Java code looks so much like C++ code it's not even funny.
I know only the basic C++ line for printing line and by looking at that it is so different. But if Pawn is similar to C++, then I agree with you!


Re: Need help again... - brandonio21 - 08-21-2012

Moldraxian Wrote:Wow. Java code looks so much like C++ code it's not even funny.
Haha, well Java is a C based language, meaning that it is syntactically similar. They operate in very different ways, but yes, Java does look like C.


Re: Need help again... - Aaron Rogers118 - 09-12-2012

How did they mace all these progaming Languages any way?????