這些線路對他們的錯誤bs.show
和g.dispose
有錯誤語法錯誤標識符想到這個令牌和部分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();
}
}
請 - 嘗試並在您的問題中鍵入一些適當的英語。我不知道什麼是錯誤信息,什麼是問題。 – 2014-01-08 01:48:23
第一步將修復您的縮進。你的代碼現在很難閱讀。另外,請發佈您收到的任何編譯器錯誤的完整文本,並指出每個引用的哪一行。 –
沒有辦法完整的源代碼,沒有類聲明... – MadProgrammer