1 Packagetest.com;2 3 Importjava.awt.GridLayout;4 5 Importjavax.swing.*;6 /*7 * Displays a frame with 9 labels with 3 types of graphics. Circles, forks and blanks8 * Random display per run9 */Ten Public classGameextendsJFrame { One PrivateImageIcon x =NewImageIcon ("D:\\x.jpg"); A PrivateImageIcon o =NewImageIcon ("D:\\o.jpg"); - PrivateImageIcon W =NewImageIcon ("D:\\w.jpg"); - the - Public Static voidMain (string[] args) { -Game Picturegame =NewGame (); -Picturegame.settitle ("Pictruegame"); +Picturegame.setsize (400, 400); -Picturegame.setlocationrelativeto (NULL); + picturegame.setdefaultcloseoperation (jframe.exit_on_close); APicturegame.setvisible (true); at - - } - - //Create a GridLayout layout - PublicGame () { inSetLayout (NewGridLayout (3,3,5,5)); - This. Random (); to } + - //methods of random display the Public voidrandom () { * intj = 0; $ while(j<9){Panax Notoginseng inti = (int) (Math.random ()); - Switch(i) { the Case0 : +AddNewJLabel (o)); Break; A Case1 : theAddNewJLabel (x)); Break; + Case2 : -AddNewJLabel (w)); Break; $ } $J + +; - } - } the}
Little practice.
There seems to be nothing to pay attention to.
Java language Programming BASIC programming exercises 12.7