java - How can I add a JPanel directly over another one in an array? -
i'm trying make board game cs course.. i've built basic board putting jpanels next each other, want add checkers on top of jpanels whenever move them, original jpanel making basic board appears.. possible? that's code:
import java.awt.*; import javax.swing.*; public class loa extends jframe{ static jpanel[][] board; static color temp; static color col1 = color.dark_gray; static color col2 = color.light_gray; public static void main (string [] args){ jframe loa = new jframe(); board = new jpanel[8][8]; loa.setlayout(new gridlayout(8, 8)); for(int i=0; i<8; i++) { if (i%2 == 0) { temp = col1; } else { temp = col2; } for(int j=0; j<8; j++) { board[i][j]= new tiles(temp); loa.getcontentpane().add(board[i][j],i,j); if (temp.equals(col1)) { temp = col2; } else { temp = col1; } } } for(int i=0; i<8; i++) { for(int j = 0; j<8; j++){ if (i < 7 && > 0 && (j == 0 || j == 7)) { board[i][j] = (jpanel) board[i][j].add(new checkers(color.black)); } if (j < 7 && j > 0 && (i == 0 || == 7)) { board[i][j] = (jpanel) board[i][j].add(new checkers(color.white));; } loa.getcontentpane().add(board[i][j],i,j); } } loa.setsize(600, 600); loa.setvisible(true); loa.setlocationrelativeto(null); loa.setdefaultcloseoperation(jframe.exit_on_close); } }
if actual checkers , tiles classes needed, i'll post em here.. they're jpanel paintcomponent()
method, tiles responsible board , checkers i'd want draw oval on top of board jpanel.. answers appreciated.
Comments
Post a Comment