找回密碼 或 安全提問
 註冊
|註冊|登錄

伊莉討論區

搜索
請尊重及感激所有版主付出和奉獻尊貴會員無限下載附件伊莉需要你的贊助和支持
刀劍神域無碼七龍珠ntr新竹office
無修正island無修正無碼上原 罵不想成為ssis

休閒聊天興趣交流學術文化旅遊交流飲食交流家庭事務PC GAMETV GAME
熱門線上其他線上感情感性寵物交流家族門派動漫交流貼圖分享BL/GL
音樂世界影視娛樂女性頻道潮流資訊BT下載區GB下載區下載分享短片
電腦資訊數碼產品手機交流交易廣場網站事務長篇小說體育運動時事經濟
上班一族博彩娛樂

[繁]格林童話變奏曲02

[繁]怪獸八號02-

[簡]單人房、日照一般

[繁]戰隊大失格03-

[繁]從Lv2開始開外掛

[簡]狼與辛香料 Merch
C & C++ 語言C# 語言Visual Basic 語言PHP 語言JAVA 語言
查看: 2718|回復: 0
打印上一主題下一主題

[分享]新手的圈圈叉叉[複製鏈接]

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
4539
積分
17830 點
潛水值
172133 米
跳轉到指定樓層
樓主
發表於 2014-5-25 04:59 PM|只看該作者|倒序瀏覽
若有安裝色情守門員,可用無界、自由門等軟件瀏覽伊莉。或使用以下網址瀏覽伊莉: http://www.eyny.com:81/index.php
本帖最後由 missu0524 於 2014-5-25 05:01 PM 編輯

新手練習「圈圈叉叉」使用工具:Eclipse

  1. import java.awt.Button;
  2. import java.awt.Frame;
  3. import java.awt.Label;
  4. import java.awt.PopupMenu;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.WindowEvent;
  8. import java.awt.event.WindowListener;


  9. public class Game1 implements WindowListener, ActionListener{

  10.         Frame fr;
  11.         Button[] btn;
  12.         String[] cm = {"0","1","2","3","4","5","6","7","8"};
  13.         boolean b = true;
  14.         int count = 0;
  15.         Game1() {
  16.                 loadGUI();
  17.         }
  18.         
  19.         public void loadGUI() {
  20.                 fr = new Frame("圈圈叉叉");
  21.                 btn = new Button[9];
  22.                 fr.setBounds(200,200,340,340);
  23.                 for (int i=0; i<btn.length; i++)
  24.                         btn[i] = new Button();
  25.                 btn[0].setBounds(20,30,100,100);
  26.                 btn[1].setBounds(120,30,100,100);
  27.                 btn[2].setBounds(220,30,100,100);
  28.                 btn[3].setBounds(20,130,100,100);
  29.                 btn[4].setBounds(120,130,100,100);
  30.                 btn[5].setBounds(220,130,100,100);
  31.                 btn[6].setBounds(20,230,100,100);
  32.                 btn[7].setBounds(120,230,100,100);
  33.                 btn[8].setBounds(220,230,100,100);
  34.                 fr.setLayout(null);
  35.                 for (int i=0; i<btn.length; i++) {
  36.                         btn[i].setActionCommand(cm[i]);
  37.                         btn[i].addActionListener(this);
  38.                         fr.add(btn[i]);
  39.                 }
  40.                 fr.setResizable(false);
  41.                 fr.addWindowListener(this);
  42.                 fr.setVisible(true);
  43.         }
  44.         
  45.         public void reset() {
  46.                 for (int i=0; i<btn.length; i++) {
  47.                         btn[i].setLabel("");
  48.                         count = 0;
  49.                         b = true;
  50.                 }
  51.         }
  52.         
  53.         //012
  54.         //345
  55.         //678
  56.         public void checkWin(int i, String s) {
  57.                 int j = 0,h = 0;
  58.                 count += 1;
  59.                 for (int k=0; k<3; k++) {
  60.                         if (btn[j].getLabel() == btn[j+1].getLabel() && btn[j+1].getLabel() == btn[j+2].getLabel() && btn[j].getLabel() != "") {
  61.                                 fr.setTitle(btn[j].getLabel() +" 獲勝");
  62.                                 reset();
  63.                         }
  64.                         j += 3;
  65.                 }
  66.                 for (int k=0; k<3; k++) {
  67.                         if (btn[h].getLabel() == btn[h+3].getLabel() && btn[h+3].getLabel() == btn[h+6].getLabel() && btn[h].getLabel() != "") {
  68.                                 fr.setTitle(btn[h].getLabel() +" 獲勝");
  69.                                 reset();
  70.                         }
  71.                         h += 1;
  72.                 }
  73.                 if (btn[0].getLabel() == btn[4].getLabel() && btn[4].getLabel() == btn[8].getLabel() && btn[0].getLabel() != "") {
  74.                         fr.setTitle(btn[0].getLabel() +" 獲勝");
  75.                         reset();
  76.                 } else if (btn[2].getLabel() == btn[4].getLabel() && btn[4].getLabel() == btn[6].getLabel() && btn[2].getLabel() != "") {
  77.                         fr.setTitle(btn[2].getLabel() +" 獲勝");
  78.                         reset();
  79.                 }
  80.                 if (count == 9){
  81.                         fr.setTitle("平手");
  82.                         reset();
  83.                 }
  84.         }
  85.         
  86.         /**
  87.          * 圈圈叉叉
  88.          */
  89.         public static void main(String[] args) {
  90.                 new Game1();
  91.         }




  92.         public void windowActivated(WindowEvent e) {
  93.         }
  94.         public void windowClosed(WindowEvent e) {
  95.         }
  96.         public void windowClosing(WindowEvent e) {
  97.                 fr.dispose();        
  98.         }
  99.         public void windowDeactivated(WindowEvent e) {
  100.         }
  101.         public void windowDeiconified(WindowEvent e) {
  102.         }
  103.         public void windowIconified(WindowEvent e) {
  104.         }
  105.         public void windowOpened(WindowEvent e) {
  106.         }
  107.         public void actionPerformed(ActionEvent e) {
  108.                 for (int i=0; i<btn.length; i++) {
  109.                         if (e.getActionCommand() == cm[i] && btn[i].getLabel() == "") {
  110.                                 if (b == true) {
  111.                                 btn[i].setLabel("O");
  112.                                 b = false;
  113.                                 checkWin(i,"O");
  114.                                 } else {
  115.                                 btn[i].setLabel("X");
  116.                                 b = true;
  117.                                 checkWin(i,"X");
  118.                                 }
  119.                         }
  120.                 }
  121.         }
  122. }
複製代碼



...
瀏覽完整內容,請先 註冊登入會員
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊
分享分享0收藏收藏0支持支持0
所有積分大於負-100的壞孩子,將可獲得重新機會成為懲罰生,權限跟幼兒生一樣。

使用道具檢舉

您需要登錄後才可以回帖 登錄 | 註冊

Powered by Discuz!

© Comsenz Inc.

重要聲明:本討論區是以即時上載留言的方式運作,對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿上傳和撰寫 侵犯版權(未經授權)、粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。
回頂部