-2
我試圖創建一個既有文本又有圖形版本的小圖形遊戲。對於這兩個版本,我使用了一個render()方法,將所有東西都繪製到板子上(在這種情況下,會將其繪製到JFrame中)。但是,我在嘗試將方法添加到JFrame時遇到問題。我想知道如何做到這一點,如果我不能做我還能做什麼。我如何實現render()方法到我的JFrame中
// Rows
for (int x = 0; x < this.cells.length; x++) {
// Columns
for (int y = 0; y < this.cells[x].length; y++) {
if (this.cells[x][y].type == Cell.EMPTY) {
g.setColor(Color.black);
g.drawOval(x, y, 10, 10);
} else if (this.cells[x][y].type == Cell.MONSTER) {
g.setColor(Color.red);
Polygon poly = new Polygon();
poly.addPoint(x, y);
poly.addPoint(x - 10, y - 10);
poly.addPoint(x + 10, y + 10);
g.drawPolygon(poly);
}
這是渲染方法,其通過搜索單元陣列和基於對象的在其x和y的類型,將以此爲根據的形狀。雖然,我對編程世界比較陌生,但我會很感激所有我能得到的幫助!
http://stackoverflow.com/questions/2134840/drawing-on-jframe – BitNinja
爲了更好地幫助越早,張貼[MCVE(http://stackoverflow.com/help/mcve)(最小完整和可驗證示例)。 –