【发布时间】:2014-01-25 22:56:46
【问题描述】:
这些行上有错误,bs.show 和 g.dispose 在此标记之后有错误语法错误标识符 expect,g.drawImage 的一部分表示删除标记和
说在这个令牌之后说语法错误 decleratorid 我做错了什么
g.drawImage(img, 0, 0, WIDTH HEIGHT, null);
g.dispose();
bs.show();
这是完整的代码
package com.mime.WorldExplorer;
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
public static final String TITLE = "World explorer(Name not final) Pre-Alpha 0.0.1";
private static final String createBufferStrategy = null;
private Thread thread;
private BufferedImage img;
private boolean running = false;
private Render render;
private Screen screen;
private int[]pixels;
private int i;
private BufferStrategy bs;
public Display() {
screen = new Screen(HEIGHT, WIDTH);
img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
pixels = ((DataBufferedInt)img.getRaster().getDataBuffer()).getData;
}
private void start() {
if (running)
return;
running = true;
thread = new Thread(this); }
private void stop() {
if(running)
return;
running = false;
try {
thread.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
public void run() {
while(running);
tick();
render();
}
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
for (int i = 0; i<(WIDTH*HEIGHT); i++);
pixels[i] = screen.pixels[i];
}
Graphics g = bs.getDrawGraphics();
g.drawImage(img, 0, 0, WIDTH, HEIGHT, null);
g.dispose();
bs.show();
private void tick() {
}
public static void main(String[] args) {
Display game = new Display();
JFrame frame = new JFrame();
frame.add(game);
frame.pack();
frame.setTitle(TITLE);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(true);
frame.setVisible(true);
System.out.println("Running....");
System.out.println("Working!");
game.start();
}
}
【问题讨论】:
-
请尝试在您的问题中输入一些正确的英语。我不知道什么是错误消息和什么问题。
-
第一步是修复缩进。您的代码很难按原样阅读。另外,请发布您遇到的任何编译器错误的全文,并准确指出每个错误所指的行。
-
不可能是完整的源代码,没有类声明...
-
错误是它在 g.dispose 和 bs.show 上说需要一个标识符,而在 drawImage 上却说是 Variabledelorater 预期的
-
再次检查这些代码行是否属于一个方法:数一下你的括号。