我有这个程序:
package com.systino.drzzle;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import com.sun.prism.Graphics;
import com.sun.prism.paint.Color;
public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width/16*9;
public static int scale = 3;
private Thread thread;
private JFrame frame;
private boolean running = false;
public Game () {
Dimension size = new Dimension(width*scale, height*scale);
setPreferredSize(size);
frame = new JFrame();
}
public synchronized void start () {
running = true;
thread = new Thread(this, "Display");
thread.start();
}
public synchronized void stop () {
running = false;
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void run () {
while (running) {
update();
render();
}
}
public void update () {
}
public void render () {
BufferStrategy bs = getBufferStrategy ();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = (Graphics) bs.getDrawGraphics();
g.setColor(Color.BLACK); //Error is shown here..
g.fillRect(0, 0, getWidth(), getHeight());
((java.awt.Graphics) g).dispose();
bs.show();
}
public static void main (String args[]) {
Game game = new Game();
game.frame.setResizable(false);
game.frame.setTitle("Drizzle");
game.frame.add(game);
game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
game.start();
}
}
编译器抱怨Graphics.setColor
是未定义的方法。
我已导入BufferStrategy
以及Graphics
和Color
。
我需要导入其他东西吗?
我正在使用Eclipse第2版(4.4.2)
答案 0 :(得分:0)
我删除了导入com.sun.prism.paint.Color并且它有效,不知道为什么我希望它有所帮助。