所以,我正在关注一个教程,我完全按照它,但是当我测试时,它会抛出一个
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - constructor Main in class spritesheet.Main cannot be applied to given types;
required: java.awt.Color
found: no arguments
reason: actual and formal argument lists differ in length
at spritesheet.Main.main(Main.java:48)
Java Result: 1
错误!
这是我的代码:
package spritesheet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
public class Main extends JFrame {
BufferedImage sprite;
private final Color Color;
public Main(Color white){
setSize(800, 600);
setVisible(true);
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setBackground(Color=white);
init();
}
private void init(){
BufferedImageLoader loader = new BufferedImageLoader();
BufferedImage spriteSheet = null;
try {
spriteSheet = loader.loadImage("spritesheet.png");
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
SpriteSheet ss = new SpriteSheet(spriteSheet);
sprite = ss.grabSprite(0, 0, 16, 16);
}
@Override
public void paint(Graphics g){
g.drawImage(sprite, 100, 100, null);
repaint();
}
public static void main(String[] args) {
Main Main = new Main();
}
}
此代码旨在在白色背景上显示静止图像,但它要么引发错误,要么显示透明背景。然后它会出错并让我烦恼。:( 我究竟做错了什么????