我編寫我的一個類時出現錯誤。語法錯誤'class'@ expected [JAVA - LWJGL]
我的進口,
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import java.util.Random;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class InputDemo{
public InputDemo(){
int height = 720;
int width = 1280;
try {
Display.setDisplayMode(new DisplayMode(1280, 720));
Display.setTitle("Input Demonstration");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
//Initialization code OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1280.0, 720.0, 0.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
while(!Display.isCloseRequested()) {
//Render (Quads are X, Y (Across, Up + Down))
glClear(GL_COLOR_BUFFER_BIT);
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
{
Display.destroy();
System.exit(0);
}
int dx = Mouse.getDX();
int dy = -Mouse.getDY();
System.out.println(dx + ", " + dy);
Display.update();
Display.sync(60);
}
Display.destroy();
}
private static class Box{
public int x, y;
public boolean selected = false;
private float colorRed, colorBlue, colorGreen;
Box(int x, int y)
{
this.x = x;
this.y = y;
Random randomGenerator = new Random();
colorRed = randomGenerator.nextFloat();
colorBlue = randomGenerator.nextFloat();
colorGreen = randomGenerator.nextFloat();
}
boolean inBounds(int mousex, int mousey)
{
if(mousex > x && mousex < x + 50 && mousey > y && < y + 50)
return true;
else
return false;
}
void update(int dx, int dy)
{
x += dx;
y += dy;
}
void randomizeColors()
{
Random randomGenerator = new Random();
colorRed = randomGenerator.nextFloat();
colorBlue = randomGenerator.nextFloat();
colorGreen = randomGenerator.nextFloat();
}
void draw()
{
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + 50, y);
glVertex2f(x + 50, y + 50);
glVertex2f(x, y + 50);
glEnd();
}
}
/**
* @param args
*/
public static void main(String[] args) {
new InputDemo();
}
}
錯誤是階級 '的語法錯誤',@預計' 藏漢爲, '插入 '}' 來完成塊'
另外,你可以看到draw()的錯誤,因爲我不能,但是glBegin不工作,因爲'GL_QUADS不是一個變量,但我找不到我用它作爲變量的位置。 ..'
非常感謝,我總是那樣做,現在只是潛意識,我必須記住這一點。非常感謝你們兩位。 – user1448741 2012-07-17 14:17:27