我有这段代码。我想添加一些命令,以便从 drawgrid
与“konichiwa”一起出现在 JPanel
事情我试过使用谷歌上的一些命令,比如。 JTable table = new JTable(rec, header);
. 我还没有找到其他方法将表实现到面板中,所以如果有人能建议一个可能有效的命令。
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableModel;
@SuppressWarnings({"serial", "unused"})
public class OnO extends JPanel {
public static void main(String[] argv) throws Exception {
int i = yesno("Play game? D:");
if (i == JOptionPane.YES_OPTION) {
JFrame f = new JFrame("WELCOME!"); // initializes objects from class JFrame
JLabel label1 = new JLabel("konichiwa"); // initializes objects from class JLabel
f.add(label1); // f calls the add function
f.pack(); // f calls the pack function
JTable table = new JTable(d);
f.add(new JScrollPane(table));
f.add(table);
f.setSize(550, 400);
f.setVisible(true); // f calls the set visible function
// when program gets big, need a way to route
} else {
System.exit(0);
}
}
public static int yesno(String theMessage) {
int result = JOptionPane.showConfirmDialog(null, theMessage,
"WELCOME", JOptionPane.YES_NO_OPTION);
return result;
}
public static String drawgrid() {
String s = null;
int[][] board = new int[16][16];
int i;
int j;
Random r = new Random();
int low = 0;
int high = 2;
for (i = 0; i < 16; i++) {
for (j = 0; j < 16; j++) {
int result = r.nextInt(high - low) + low;
board[i][j] = result;
}
}
for (int[] row : board) {
printRow(row);
}
return s;
}
public static void printRow(int[] row) {
for (int i : row) {
System.out.print(i);
System.out.print("\t");
}
System.out.println();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!