내 Game of Life 프로젝트를 마무리하는 데 어려움을 겪고 있습니다. 알고리즘과 기능이 모두 있지만 디스플레이가 표시되지 않습니다. 누구든지 도와 주겠니? 미리 감사드립니다.Java - Life of Game - 그래픽 표시에 문제가 있습니다.
클래스 ActiveFrame
import java.awt.*;
import java.awt.event.*;
public class ActiveFrame extends Frame {
//inherits from Frame class, but (Frame doesn't allow user to click out of extra window)
//Allows user to "x" out of window
//************
//Constructors
//************
public ActiveFrame(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setSize(300, 250);
setTitle(getClass().getName());}
}
클래스 GoLWorldMainCS
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JOptionPane;
public class GoLWorldMainCS extends ActiveFrame {
public static void main(String[] args){
boolean cont;
GoLWorldCS terrain = new GoLWorldCS();
terrain.setSize(Integer.parseInt(JOptionPane.showInputDialog("Enter rows: ")),
Integer.parseInt(JOptionPane.showInputDialog("Enter cols: ")));
terrain.setGenerations(Integer.parseInt(JOptionPane.showInputDialog("Enter generations: ")));
if (terrain.getRow() > 60 ||
terrain.getRow() < 1 ||
terrain.getCol() > 60 ||
terrain.getCol() < 1 ||
terrain.getGenerations() < 1
){
System.out.println("Error: Rows and Columns must be 1-60, and Generations must be greater than 0.");
}
else {
terrain.setCellSize((600/terrain.getRow()), (600/terrain.getCol()));
terrain.clearGrid();
cont = true;
while (cont == true){
terrain.setCells(terrain.getC(), terrain.getR(), 1);
terrain.setCells(Integer.parseInt(JOptionPane.showInputDialog("Enter x-coordinate of live cell (999 to stop): ")),
Integer.parseInt(JOptionPane.showInputDialog("Enter y-coordinate of live cell (0 to stop): ")),
Integer.parseInt(JOptionPane.showInputDialog("Enter live row length (0 to stop)")));
if(terrain.getR() == 999){
cont = false;
}
else{
if(terrain.getR() >= 0 && terrain.getR() <= terrain.getRow() &&
terrain.getC() >= 0 && terrain.getC() <= terrain.getCol() &&
terrain.getL() >= 0 && terrain.getL() <= (terrain.getRow() - terrain.getC() + 1)){
terrain.markAlive();
terrain.showDisplay();
}
else{ System.out.println("Entered coordinate out of bounds");}
}
}
}
}
}
클래스 GoLWorldCS 있었다
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class GoLWorldCS extends ActiveFrame {
int maxRow;
int maxCol;
int gen;
int buckets [][] = new int [maxRow][maxCol];
int r=0, c=0, l=1;
int xDist, yDist;
public GoLWorldCS(){
}
public void clearGrid(){
while (r<=maxRow-1){
c=0;
while (c<=maxCol-1){
buckets[r][c] = 0;
c=c+1;
}
r=r+1;
}
}
public void markAlive(){
while (l > 1){
buckets[r][c] = 1;
c++;
l--;
}
}
public void showDisplay(Graphics g){
r = 0;
c = 0;
g.setColor(Color.blue);
while (r<=maxRow-1){
c=0;
while (c<=maxCol-1){
if (buckets[r][c] != 0) {
g.fillOval((c)*xDist + 50, (r)*yDist + 50, xDist, yDist);
System.out.println(r + " " + c);
}
c=c+1;
}
r=r+1;
}
}
public void setCellSize(int width, int height){
this.xDist = width;
this.yDist= height;
}
public void setSize(int maxR, int maxC){
this.maxRow = maxR;
this.maxCol = maxC;
}
public void setGenerations(int gens){
this.gen = gens;
}
public void setCells(int R, int C, int L){
this.r = R;
this.c = C;
this.l = L;
}
public int getRow(){
return maxRow;
}
public int getCol(){
return maxCol;
}
public int getGenerations(){
return gen;
}
public int getR(){
return r;
}
public int getC(){
return c;
}
public int getL(){
return l;
}
private static void main(String[] args)
{
GoLWorldMainCS aframe = new GoLWorldMainCS();
aframe.setSize(700,700);
aframe.setLocation(50,50);
aframe.setTitle("Game of Life");
aframe.show();
}
}
당신은 코드를 통해 걸어? 어디에서 그래픽이 보이기를 기대합니까? 너 뭐 해봤 니? –
아마도 [이 기사] (http://java-articles.info/articles/?p=504)에서 몇 가지 아이디어를 얻을 수 있습니다. –