PackageCom.niit.javagui;Importjava.awt.BorderLayout;ImportJava.awt.Color;Importjava.awt.GridBagConstraints;Importjava.awt.GridLayout;ImportJava.awt.Label;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JLabel;ImportJavax.swing.JPanel;ImportJavax.swing.border.Border;/** * @author: Annie * @date: May 30, 2016 * @description: Chess board*/ Public classWingridextendsjframe{ Public Static voidMain (string[] args) {NewWingrid (); } GridLayout grid; JPanel chessboard; PublicWingrid () {grid=NewGridLayout (12, 12); Chessboard=NewJPanel (); Chessboard.setlayout (GRID); label[][] Label=NewLabel[12][12]; for(inti = 0; i < label.length; i++) { for(intj = 0; J < Label.length; J + +) {Label[i][j]=NewLabel (); if((I+J)%2==0) Label[i][j].setbackground (Color.Black); ElseLabel[i][j].setbackground (Color.White); Chessboard.add (Label[i][j]); }} Add (Chessboard,borderlayout.center); Add (NewJButton ("Northern combatants"), Borderlayout.north); Add (NewJButton ("South combatant"), Borderlayout.south); Add (NewJButton ("Western Combatants"), borderlayout.west); Add (NewJButton ("The Eastern combatants"), borderlayout.east); SetBounds (10, 10, 570, 390); SetVisible (true); Setdefaultcloseoperation (Jframe.exit_on_close); Validate (); }}
:
GUI (chess board)