java - How to get the board without maximize then minimize -
i try make board game in java have problem in board must maximize minimize window wanted board make class of square takes color , position , 1 board
package eg.edu.guc.loa.gui; import java.awt.borderlayout; import java.awt.color; import java.awt.component; import java.awt.gridlayout; import javax.swing.jframe; import javax.swing.jpanel; public class boardgui extends jframe { public boardgui() { setsize(600, 600); setvisible(true); getcontentpane().setlayout(new gridlayout(8,8)); jpanel [][]board= new jpanel[8][8]; for(int i=0;i<8;i++) { for(int j=0;j<8;j++) { if(i%2==0) { if(j%2==0) { board[i][j]=new square(color.black,0); add(board[i][j],borderlayout.center); } else { if(j%2!=0) { board[i][j]=new square(color.white,0); add(board[i][j],borderlayout.center); } } } else { if(i%2!=0) { if(j%2==0) { board[i][j]=new square(color.white,0); add(board[i][j]); } else { if(j%2!=0) { board[i][j]=new square(color.black,0); add(board[i][j]); } } } } } } setextendedstate(getextendedstate()|jframe.maximized_both) } }
and here square class
package eg.edu.guc.loa.gui; import java.awt.color; import java.awt.graphics; import javax.swing.jpanel; public class square extends jpanel { private color c; private int x; public square(color c,int x) { this.x=x; this.c=c; } public void paint(graphics g) { super.paint(g); g.drawrect(x,x, 80,80); g.setcolor(c); g.fillrect(x,x,80,80); } }
Comments
Post a Comment