0
我目前有一個3類java應用程序,我正嘗試使用JavaFX創建一個簡單的遊戲。在我的GameCore類中,我試圖創建一個gameGrid的實例。但是當我使用「grid = new gameGrid(int,int,int,int);」 eclipse告訴我gameGrid是未定義的,並建議我創建方法,當我按照eclipse的要求做時,它會在我的gameCore類中放置一個私有方法gameGrid,但gameGrid應該是gameGrid.class的構造方法。我已經重新啓動了這個項目並清理了這個項目,但是無濟於事。Java - 未定義在Eclipse中的方法
public class gameCore {
gameGrid grid;
public gameCore(){
getGrid();
}
public void getGrid(){
grid = gameGrid(32, 32, 10, 10); //Error is here, underlining "gameGrid"
//Also using gameGrid.gameGrid(32,32,10,10); does not work either, still says its undefined
/*
This is the code that Eclipse wants to place when I let it fix the error, and it places this code in this class.
private gameGrid gameGrid(int i, int j, int k, int l) {
// TODO Auto-generated method stub
return null;
}
*/
}
}
public class gameGrid {
protected int[][] grid;
protected int tileWidth;
protected int tileHeight;
public gameGrid(int tileWidth, int tileHeight, int horizTileCount, int vertTileCount){
//Create Grid Object
grid = new int[vertTileCount][];
for(int y = 0; y < vertTileCount; y++){
for(int x = 0; x < horizTileCount; x++){
grid[y] = new int[horizTileCount];
}
}
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
}
}
import java.awt.Dimension;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class gameGUI extends Application {
Dimension screenDimensions = new Dimension(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
public static void main(String[] args){
launch(args);
}
public void start(Stage stage) throws Exception {
Canvas c = new Canvas();
StackPane sp = new StackPane();
Scene scene = new Scene(sp, screenDimensions.width, screenDimensions.height);
sp.getChildren().add(c);
stage.setScene(scene);
gameCore game = new gameCore();
stage.show();
}
}
謝謝!這解決了它,不知道我怎麼錯過了,可能需要睡一會兒......我也重新命名了我的課程,我知道,但有一段時間沒有做一個嚴重的Java程序,感謝提醒.. 。 – Metroidaron