幾個星期前我剛開始學習Java,所以我很新。我目前正在開發一個TicTacToe遊戲,並且我剛剛完成了,但是我沒有將自己的主板顯示爲System.out.print,而是希望它顯示在JOptionPane消息上,而不是從美學角度進行改進。不過,我的板完全是用循環制成的,我不知道如何在JOptionPane上顯示它:(我嘗試過在線研究類似情況,但是我發現的一切都很混亂,或者似乎不適用於這種類型聲明我打印的。如果有人可以幫助我將非常感激。在單個JOptionPane中顯示多個System.out.print?
public static void showBoard(char[][] brd)
{
int numRow = brd.length;
int numCol = brd[0].length;
System.out.println();
// This is the column
System.out.print(" ");
for (int i = 0; i < numCol; i++)
System.out.print(i + " ");
System.out.print('\n');
System.out.println(); // blank line after the header
// The write the table
for (int i = 0; i < numRow; i++) {
System.out.print(i + " ");
for (int j = 0; j < numCol; j++) {
if (j != 0)
System.out.print("|");
System.out.print(" " + brd[i][j] + " ");
}
System.out.println();
if (i != (numRow - 1)) {
// separator line
System.out.print(" ");
for (int j = 0; j < numCol; j++) {
if (j != 0)
System.out.print("+");
System.out.print("---");
}
System.out.println();
}
}
System.out.println();
}
我不認爲'JOptionPane'真的是你想要的。查看[使用JFC/Swing創建GUI](http://docs.oracle.com/javase/tutorial/uiswing/),瞭解如何構建用戶界面 – MadProgrammer 2014-12-04 01:08:19
使用'StringBuilder',[例子](http ://stackoverflow.com/a/14011536/230513)。 – trashgod 2014-12-04 01:33:04