Java語言程式設計 基礎篇 編程練習題 12.7

來源:互聯網
上載者:User

標籤:tcl   xtend   random   operation   需要   this   set   size   imp   

 1 package test.com; 2  3 import java.awt.GridLayout; 4  5 import javax.swing.*; 6     /* 7      * 顯示一個包含9個標籤的架構,標籤有3類圖形。圈、叉和空白 8      * 每次運行隨機顯示 9      */10 public class Game extends JFrame {11     private ImageIcon x = new ImageIcon("d:\\x.jpg");12     private ImageIcon o = new ImageIcon("d:\\o.jpg");13     private ImageIcon w = new ImageIcon("d:\\w.jpg");14     15     16     public static void main(String[] args) {17         Game pictureGame = new Game();18         pictureGame.setTitle("pictrueGame");19         pictureGame.setSize(400, 400);20         pictureGame.setLocationRelativeTo(null);21         pictureGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);22         pictureGame.setVisible(true);23         24         25     }26     27     //建立一個GridLayout布局28     public Game(){29         setLayout(new GridLayout(3,3,5,5));30         this.random();31     }32     33     //隨機顯示的方法34     public void random(){35         int j = 0;36         while(j<9){37             int i = (int) (Math.random()*3);38             switch(i){39             case 0 : 40                 add(new JLabel(o));break;        41             case 1 : 42                 add(new JLabel(x));break;43             case 2 : 44                 add(new JLabel(w));break;45             }46             j++;47         }48     }49 }

小練習。

好像沒有什麼需要注意的東西。

Java語言程式設計 基礎篇 編程練習題 12.7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.