Public classSnakepanelextendsjpanel{Private Static Final LongSerialversionuid = 1L; intX_width = 40; intY_height = 30; Boolean[][]map =New Boolean[Y_height][x_width]; voidInitmap () { for(inti = 0; i < map.length; i++) { for(intj = 0; J < Map[i].length; J + +) { if(i==0 | | i==map.length-1 | | j==0 | | j==map[i].length-1) Map[i][j]=true; //Else//Map[i][j] = false; default is False } } } intCell_width = 20; intCell_height = 20; @Override Public voidPaint (Graphics g) {Super. Paint (g); //the outer loop controls the number of rows, which is the ordinate y of the current coordinates. for(inti = 0; i < map.length; i++) { //the inner loop controls the number of columns, which is the horizontal axis of the current coordinate x for(intj = 0; J < Map[i].length; J + +) { if(Map[i][j]) G.setcolor (Color.dark_gray); ElseG.setcolor (Color.White); G.fill3drect (J*cell_width, I*cell_height, Cell_width, Cell_height,true); } } } Public Static voidMain (string[] args) {Snakepanel sp=NewSnakepanel (); for(inti = 0; i < sp.map.length; i++) { for(intj = 0; J < Sp.map[i].length; J + +) {System.out.print (sp.map[i][j]); } System.out.println (); } }}
The bottom and wall of the 3D effect