Guest User

Untitled

a guest
Jan 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.22 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class DancingWithTheCriminals
  6. {
  7.  
  8. static JFrame frm=new JFrame("犯人在跳舞");
  9. static JPanel palPlayers[]=new JPanel[8],
  10. palSkill[]=new JPanel[4];
  11. static JButton btnStart=new JButton("Start"),
  12. btnScore=new JButton("Score"),
  13. btnExit=new JButton("Exit"),
  14. btnYes=new JButton("YES"),
  15. btnNo=new JButton("NO"),
  16. btnBack=new JButton("Back"),
  17. btnPageup=new JButton(),
  18. btnPagedown=new JButton(),
  19. btnSkip=new JButton("Skip"),
  20. btnReady=new JButton("Ready?"),
  21. btnGo=new JButton("GO!"),
  22. btnSkipYes=new JButton("YES"),
  23. btnSkipNo=new JButton("NO"),
  24. btnOK=new JButton("OK");
  25. static JLabel labTutorial=new JLabel(),
  26. labSequence[]=new JLabel[8],
  27. labRound=new JLabel("Round",JLabel.CENTER),
  28. labCardOut=new JLabel(),
  29. labCards[]=new JLabel[32],
  30. labOK=new JLabel("OK",JLabel.CENTER),
  31. labSkill[]=new JLabel[4];
  32. static JDialog dlgExit=new JDialog(frm,"Exit",true),
  33. dlgSkip=new JDialog(frm,"Skip",true);
  34. static ImageIcon ImgTutorial[]=new ImageIcon[6];
  35. static Container cp=frm.getContentPane();
  36. static CardLayout card=new CardLayout();
  37. static int index=0, //當前顯示的圖
  38. sequence=0; //顯示當前玩家
  39. static boolean cardChoose[]=new boolean[4], //判斷卡片是否被選取
  40. cardUsed[]=new boolean[4], //判斷卡片是否已使用
  41. OKClicked=false; //判斷OK按鈕是否按下
  42.  
  43. public static void main(String args[])
  44. {
  45. JPanel palMain=new JPanel(),
  46. palExit=new JPanel(),
  47. palScore=new JPanel(),
  48. palTutorial=new JPanel(),
  49. palButton=new JPanel(),
  50. palSkip=new JPanel(),
  51. palGame=new JPanel(),
  52. palGameTop=new JPanel(),
  53. palGameCenter=new JPanel(),
  54. palGameBottom=new JPanel(),
  55. palOK=new JPanel(); //****//
  56. JLabel labBackground=new JLabel(),
  57. labMainTitle=new JLabel("Title",JLabel.CENTER),
  58. labAskExit=new JLabel("Are You Sure?",JLabel.CENTER),
  59. labScoreTitle=new JLabel("Score",JLabel.CENTER),
  60. labTutorialTitle=new JLabel("Tutorial",JLabel.CENTER),
  61. labAskSkip=new JLabel("Are You Sure?",JLabel.CENTER),
  62. labPlayer=new JLabel();
  63. Font fontS=new Font("Segoe Script",Font.ITALIC+Font.BOLD,96),
  64. fontSs=new Font("Segoe Script",Font.ITALIC+Font.BOLD,48),
  65. fontS2=new Font("SketchFlow Print",Font.BOLD,30),
  66. fontK=new Font("Kristen ITC",Font.BOLD,45),
  67. fontKs=new Font("Kristen ITC",Font.BOLD,35),
  68. fontKss=new Font("Kristen ITC",Font.BOLD,25);
  69. ImageIcon Imgbg=new ImageIcon("image/Background.jpg"),
  70. ImgPgUp=new ImageIcon("image/PageUp.jpg"),
  71. ImgPgDn=new ImageIcon("image/PageDown.jpg");
  72.  
  73. //-----------------------------------------------------------------------------------------------------
  74.  
  75. //設定初值
  76.  
  77. ImgTutorial[0]=new ImageIcon("image/Tutorial0.jpg");
  78. ImgTutorial[1]=new ImageIcon("image/Tutorial1.jpg");
  79. ImgTutorial[2]=new ImageIcon("image/Tutorial2.jpg");
  80. ImgTutorial[3]=new ImageIcon("image/Tutorial3.jpg");
  81. ImgTutorial[4]=new ImageIcon("image/Tutorial4.jpg");
  82. ImgTutorial[5]=new ImageIcon("image/Tutorial5.jpg");
  83.  
  84. for(int k=0;k<4;k++)
  85. {
  86. cardChoose[k]=false;
  87. }
  88.  
  89. //-----------------------------------------------------------------------------------------------------
  90.  
  91. //視窗設置
  92. frm.setSize(1200,750);
  93. frm.setLocationRelativeTo(null);
  94. frm.setResizable(false);
  95. frm.setVisible(true);
  96. frm.setLayout(null);
  97. //Container設置
  98. cp.setLayout(card);
  99. ((JPanel)cp).setOpaque(false);
  100.  
  101. //-----------------------------------------------------------------------------------------------------
  102.  
  103. //背景
  104. labBackground.setIcon(Imgbg);
  105. labBackground.setBounds(0,0,1200,750);
  106. //add
  107. frm.getLayeredPane().add(labBackground, new Integer(Integer.MIN_VALUE));
  108.  
  109. //-----------------------------------------------------------------------------------------------------
  110.  
  111. //主畫面
  112. palMain.setLayout(null);
  113. palMain.setBounds(0,0,1200,750);
  114. palMain.setOpaque(false); //將panel設為透明化
  115. //標題
  116. labMainTitle.setFont(fontS);
  117. labMainTitle.setBounds(150,50,900,250);
  118. //labMainTitle.setForeground(Color.orange); //設定字型顏色
  119. //Start按鈕
  120. btnStart.setFont(fontKs);
  121. btnStart.setBounds(450,460,300,60);
  122. btnStart.setBorderPainted(true); //設定按鈕去邊框
  123. btnStart.setContentAreaFilled(false); //設定按鈕背景透明
  124. //Score按鈕
  125. btnScore.setFont(fontKs);
  126. btnScore.setBounds(450,530,300,60);
  127. btnScore.setBorderPainted(false);
  128. btnScore.setContentAreaFilled(false);
  129. //Eixt按鈕
  130. btnExit.setFont(fontKs);
  131. btnExit.setBounds(450,600,300,60);
  132. btnExit.setBorderPainted(false);
  133. btnExit.setContentAreaFilled(false);
  134. //add
  135. palMain.add(labMainTitle);
  136. palMain.add(btnStart);
  137. palMain.add(btnScore);
  138. palMain.add(btnExit);
  139. cp.add(palMain,"Main");
  140.  
  141. //-----------------------------------------------------------------------------------------------------
  142.  
  143. //成績畫面
  144. palScore.setLayout(null);
  145. palScore.setBounds(0,0,1200,750);
  146. palScore.setOpaque(false);
  147. //標題
  148. labScoreTitle.setFont(fontSs);
  149. labScoreTitle.setBounds(300,50,600,50);
  150. //回上一頁按鈕
  151. btnBack.setBounds(500,600,200,70);
  152. btnBack.setFont(fontKs);
  153. btnBack.setContentAreaFilled(false);
  154. //add
  155. palScore.add(labScoreTitle);
  156. palScore.add(btnBack);
  157. cp.add(palScore,"Score");
  158.  
  159. //-----------------------------------------------------------------------------------------------------
  160.  
  161. //簡介畫面
  162. palTutorial.setLayout(null);
  163. palTutorial.setBounds(0,0,1200,750);
  164. palTutorial.setOpaque(false);
  165. //標題
  166. labTutorialTitle.setFont(fontSs);
  167. labTutorialTitle.setBounds(300,50,600,50);
  168. //內容
  169. labTutorial.setOpaque(true);
  170. labTutorial.setBounds(150,130,900,450);
  171. labTutorial.setIcon(ImgTutorial[0]);
  172. //上一頁按鈕
  173. btnPageup.setIcon(ImgPgUp);
  174. btnPageup.setBounds(35,300,80,80);
  175. btnPageup.setVisible(false);
  176. btnPageup.setBorderPainted(false);
  177. btnPageup.setContentAreaFilled(false);
  178. //下一頁按鈕
  179. btnPagedown.setIcon(ImgPgDn);
  180. btnPagedown.setBounds(1085,300,80,80);
  181. btnPagedown.setBorderPainted(false);
  182. btnPagedown.setContentAreaFilled(false);
  183. //Skip按鈕
  184. btnSkip.setFont(fontKs);
  185. btnSkip.setBounds(950,25,150,60);
  186. btnSkip.setBorderPainted(false);
  187. btnSkip.setContentAreaFilled(false);
  188. //遊戲開始按鈕
  189. //按鈕面板
  190. palButton.setLayout(null);
  191. palButton.setBounds(500,600,200,90);
  192. palButton.setOpaque(false);
  193. //Ready按鈕
  194. btnReady.setFont(fontKs);
  195. btnReady.setBounds(0,20,200,70);
  196. btnReady.setContentAreaFilled(false);
  197. btnReady.setVisible(false);
  198. //Go按鈕
  199. btnGo.setFont(fontKs);
  200. btnGo.setBounds(0,20,200,70);
  201. btnGo.setContentAreaFilled(false);
  202. btnGo.setVisible(false);
  203. //add
  204. palButton.add(btnReady);
  205. palButton.add(btnGo);
  206. palTutorial.add(labTutorialTitle);
  207. palTutorial.add(labTutorial);
  208. palTutorial.add(btnSkip);
  209. palTutorial.add(btnPageup);
  210. palTutorial.add(btnPagedown);
  211. palTutorial.add(palButton);
  212. cp.add(palTutorial,"Tutorial");
  213.  
  214. //-----------------------------------------------------------------------------------------------------
  215.  
  216. //遊戲畫面
  217. palGame.setLayout(null);
  218. palGame.setBounds(0,0,1200,750);
  219. palGame.setOpaque(false);
  220. //Top
  221. palGameTop.setLayout(null);
  222. palGameTop.setBounds(0,0,1200,100);
  223. palGameTop.setOpaque(false);
  224. //回合數
  225. labRound.setBounds(0,15,250,50);
  226. labRound.setFont(fontKss);
  227. labRound.setOpaque(true);
  228. labRound.setBackground(Color.white);
  229. //出牌順序&玩家頭像們
  230. for(int k=0;k<8;k++)
  231. {
  232. palPlayers[k]=new JPanel();
  233. palPlayers[k].setLayout(null);
  234. palPlayers[k].setBounds(570+75*k,15,70,90);
  235. if(k==0)
  236. {
  237. palPlayers[k].setBackground(Color.orange);
  238. }
  239. else
  240. {
  241. palPlayers[k].setBackground(Color.white);
  242. }
  243.  
  244. labSequence[k]=new JLabel();
  245. labSequence[k].setBounds(0,0,70,70);
  246. labSequence[k].setOpaque(true);
  247. labSequence[k].setBackground(Color.pink);
  248. }
  249. //Center
  250. palGameCenter.setBounds(0,150,1200,300);
  251. palGameCenter.setOpaque(false);
  252. //出牌區
  253. labCardOut.setBounds(450,100,150,180);
  254. labCardOut.setFont(fontS);
  255. labCardOut.setOpaque(false);
  256. //Bottom
  257. palGameBottom.setLayout(null);
  258. palGameBottom.setBounds(0,450,1200,300);
  259. palGameBottom.setOpaque(false);
  260. //所有&所持卡牌
  261. for(int k=0;k<4;k++)
  262. {
  263. labCards[k]=new JLabel();
  264. labCards[k].setBounds(15*(k+1)+150*k,55,150,180);
  265. labCards[k].setOpaque(true);
  266. labCards[k].setBackground(Color.green);
  267. }
  268. //卡牌功能
  269. for(int k=0;k<4;k++)
  270. {
  271. palSkill[k]=new JPanel();
  272. palSkill[k].setLayout(null);
  273. palSkill[k].setVisible(false);
  274. palSkill[k].setBounds(15*(k+1)+150*k,355,150,150);
  275. palSkill[k].setBackground(Color.yellow);
  276.  
  277. labSkill[k]=new JLabel();
  278. labSkill[k].setBounds(10,10,130,130);
  279. labSkill[k].setOpaque(true);
  280. labSkill[k].setBackground(Color.pink);
  281. }
  282. //確定按鈕
  283. palOK.setLayout(null);
  284. palOK.setBounds(800,100,100,100);
  285. palOK.setOpaque(false);
  286. btnOK.setBounds(0,0,100,100);
  287. btnOK.setFont(fontKs);
  288. btnOK.setContentAreaFilled(false);
  289. btnOK.setVisible(false);
  290. labOK.setBounds(800,100,100,100);
  291. labOK.setFont(fontKs);
  292. labOK.setForeground(Color.red);
  293. //自己的頭像
  294. labPlayer.setBounds(1025,75,150,150);
  295. labPlayer.setOpaque(true);
  296. labPlayer.setBackground(Color.pink);
  297. //add
  298. palGameTop.add(labRound);
  299. for(int k=0;k<8;k++)
  300. {
  301. palPlayers[k].add(labSequence[k]);
  302. palGameTop.add(palPlayers[k]);
  303. }
  304. palGameCenter.add(labCardOut);
  305. palOK.add(btnOK);
  306. for(int k=0;k<4;k++)
  307. {
  308. palGameBottom.add(labCards[k]);
  309. }
  310. palGameBottom.add(labPlayer);
  311. palGameBottom.add(labOK);
  312. palGameBottom.add(palOK);
  313. for(int k=0;k<4;k++)
  314. {
  315. palSkill[k].add(labSkill[k]);
  316. palGame.add(palSkill[k]);
  317. }
  318. palGame.add(palGameTop);
  319. palGame.add(palGameCenter);
  320. palGame.add(palGameBottom);
  321. cp.add(palGame,"Game");
  322.  
  323. //-----------------------------------------------------------------------------------------------------
  324.  
  325. //其他畫面
  326. //離開遊戲
  327. //對話框
  328. dlgExit.setLayout(null);
  329. dlgExit.setSize(600,300);
  330. dlgExit.setLocationRelativeTo(null);
  331. dlgExit.setVisible(false);
  332. dlgExit.setResizable(false);
  333. //面板
  334. palExit.setLayout(null);
  335. palExit.setBounds(0,0,600,300);
  336. //詢問標籤
  337. labAskExit.setBounds(100,50,400,50);
  338. labAskExit.setFont(fontK);
  339. //按鈕
  340. btnYes.setBounds(100,180,150,50);
  341. btnYes.setFont(fontKs);
  342. btnYes.setContentAreaFilled(false);
  343. btnNo.setBounds(350,180,150,50);
  344. btnNo.setFont(fontKs);
  345. btnNo.setContentAreaFilled(false);
  346. //add
  347. palExit.add(labAskExit);
  348. palExit.add(btnYes);
  349. palExit.add(btnNo);
  350. dlgExit.add(palExit);
  351.  
  352. //跳過教學
  353. //對話框
  354. dlgSkip.setLayout(null);
  355. dlgSkip.setSize(600,300);
  356. dlgSkip.setLocationRelativeTo(null);
  357. dlgSkip.setVisible(false);
  358. dlgSkip.setResizable(false);
  359. //面板
  360. palSkip.setLayout(null);
  361. palSkip.setBounds(0,0,600,300);
  362. //詢問標籤
  363. labAskSkip.setBounds(100,50,400,50);
  364. labAskSkip.setFont(fontK);
  365. //按鈕
  366. btnSkipYes.setBounds(100,180,150,50);
  367. btnSkipYes.setFont(fontKs);
  368. btnSkipYes.setContentAreaFilled(false);
  369. btnSkipNo.setBounds(350,180,150,50);
  370. btnSkipNo.setFont(fontKs);
  371. btnSkipNo.setContentAreaFilled(false);
  372. //add
  373. palSkip.add(labAskSkip);
  374. palSkip.add(btnSkipYes);
  375. palSkip.add(btnSkipNo);
  376. dlgSkip.add(palSkip);
  377.  
  378. //-----------------------------------------------------------------------------------------------------
  379.  
  380. //Listener設定
  381. frm.addWindowListener(new winClose());
  382. btnYes.addActionListener(new winClose());
  383. btnNo.addActionListener(new winClose());
  384. btnPageup.addActionListener(new imageChange());
  385. btnPagedown.addActionListener(new imageChange());
  386. btnStart.addMouseListener(new btnSelect());
  387. btnScore.addMouseListener(new btnSelect());
  388. btnExit.addMouseListener(new btnSelect());
  389. btnBack.addMouseListener(new btnSelect());
  390. btnSkip.addMouseListener(new btnSelect());
  391. btnSkipYes.addMouseListener(new btnSelect());
  392. btnSkipNo.addMouseListener(new btnSelect());
  393. btnReady.addMouseListener(new btnSelect());
  394. btnGo.addMouseListener(new btnSelect());
  395. btnOK.addMouseListener(new btnSelect());
  396. for(int k=0;k<4;k++)
  397. {
  398. labCards[k].addMouseListener(new Cards());
  399. }
  400.  
  401. //-----------------------------------------------------------------------------------------------------
  402.  
  403. card.show(cp,"Main");
  404. }
  405.  
  406. static class btnSelect extends MouseAdapter //按鈕選擇
  407. {
  408. public void mouseEntered(MouseEvent e)
  409. {
  410. JButton btn=(JButton)e.getSource();
  411.  
  412. if(btn==btnStart)
  413. {
  414. btnStart.setBorderPainted(true);
  415. btnScore.setBorderPainted(false);
  416. btnExit.setBorderPainted(false);
  417. }
  418. if(btn==btnScore)
  419. {
  420. btnScore.setBorderPainted(true);
  421. btnStart.setBorderPainted(false);
  422. btnExit.setBorderPainted(false);
  423. }
  424. if(btn==btnExit)
  425. {
  426. btnExit.setBorderPainted(true);
  427. btnStart.setBorderPainted(false);
  428. btnScore.setBorderPainted(false);
  429. }
  430. if(btn==btnSkip)
  431. {
  432. btnSkip.setBorderPainted(true);
  433. }
  434. if(btn==btnReady)
  435. {
  436. btnReady.setVisible(false);
  437. btnGo.setVisible(true);
  438. }
  439. }
  440. public void mouseExited(MouseEvent e)
  441. {
  442. JButton btn=(JButton)e.getSource();
  443.  
  444. if(btn==btnSkip)
  445. {
  446. btnSkip.setBorderPainted(false);
  447. }
  448. if(btn==btnGo)
  449. {
  450. btnReady.setVisible(true);
  451. btnGo.setVisible(false);
  452. }
  453. }
  454. public void mouseClicked(MouseEvent e)
  455. {
  456. JButton btn=(JButton)e.getSource();
  457.  
  458. if(btn==btnStart)
  459. {
  460. card.show(cp,"Tutorial");
  461. }
  462. if(btn==btnScore)
  463. {
  464. card.show(cp,"Score");
  465. }
  466. if(btn==btnBack)
  467. {
  468. card.show(cp,"Main");
  469. }
  470. if(btn==btnExit)
  471. {
  472. dlgExit.setVisible(true);
  473. }
  474. if(btn==btnSkip)
  475. {
  476. dlgSkip.setVisible(true);
  477. }
  478. if(btn==btnSkipYes)
  479. {
  480. dlgSkip.setVisible(false);
  481. card.show(cp,"Game");
  482. }
  483. if(btn==btnSkipNo)
  484. {
  485. dlgSkip.setVisible(false);
  486. }
  487. if(btn==btnGo)
  488. {
  489. card.show(cp,"Game");
  490. }
  491. if(btn==btnOK)
  492. {
  493. if(cardChoose[0]==true)
  494. {
  495. labCards[0].setBounds(15,55,150,180);
  496. labCards[0].setBackground(Color.black);
  497. labCardOut.setOpaque(true);
  498. labCardOut.setBackground(Color.white);
  499. labCardOut.setText("0");
  500. }
  501. if(cardChoose[1]==true)
  502. {
  503. labCards[1].setBounds(15*2+150,55,150,180);
  504. labCards[1].setBackground(Color.black);
  505. labCardOut.setOpaque(true);
  506. labCardOut.setBackground(Color.white);
  507. labCardOut.setText("1");
  508. }
  509. if(cardChoose[2]==true)
  510. {
  511. labCards[2].setBounds(15*3+150*2,55,150,180);
  512. labCards[2].setBackground(Color.black);
  513. labCardOut.setOpaque(true);
  514. labCardOut.setBackground(Color.white);
  515. labCardOut.setText("2");
  516. }
  517. if(cardChoose[3]==true)
  518. {
  519. labCards[3].setBounds(15*4+150*3,55,150,180);
  520. labCards[3].setBackground(Color.black);
  521. labCardOut.setOpaque(true);
  522. labCardOut.setBackground(Color.white);
  523. labCardOut.setText("3");
  524. }
  525.  
  526. OKClicked=true;
  527. btnOK.setVisible(false);
  528. labOK.setVisible(true);
  529. //palPlayers[sequence%8].setBackground(Color.white);
  530. //sequence++;
  531. //palPlayers[sequence%8].setBackground(Color.orange);
  532. }
  533. }
  534. }
  535.  
  536. static class imageChange implements ActionListener //遊戲教學換頁
  537. {
  538. public void actionPerformed(ActionEvent e)
  539. {
  540. JButton btn=(JButton)e.getSource();
  541.  
  542. if(btn==btnPageup&&index>0)
  543. {
  544. index--;
  545.  
  546.  
  547. }
  548. if(btn==btnPagedown&&index<5)
  549. {
  550. index++;
  551.  
  552. }
  553.  
  554. if(index==0)
  555. {
  556. btnPageup.setVisible(false);
  557. }
  558. else
  559. {
  560. btnPageup.setVisible(true);
  561. }
  562. if(index==5)
  563. {
  564. btnPagedown.setVisible(false);
  565. btnReady.setVisible(true);
  566. btnSkip.setVisible(false);
  567. }
  568. else
  569. {
  570. btnPagedown.setVisible(true);
  571. btnReady.setVisible(false);
  572. btnSkip.setVisible(true);
  573. }
  574.  
  575. labTutorial.setIcon(ImgTutorial[index]);
  576. }
  577. }
  578.  
  579. static class Cards extends MouseAdapter //卡片選擇
  580. {
  581. public void mouseEntered(MouseEvent e)
  582. {
  583. JLabel lab=(JLabel)e.getSource();
  584.  
  585. if(lab==labCards[0])
  586. {
  587. palSkill[0].setVisible(true);
  588. }
  589. if(lab==labCards[1])
  590. {
  591. palSkill[1].setVisible(true);
  592. }
  593. if(lab==labCards[2])
  594. {
  595. palSkill[2].setVisible(true);
  596. }
  597. if(lab==labCards[3])
  598. {
  599. palSkill[3].setVisible(true);
  600. }
  601. }
  602. public void mouseExited(MouseEvent e)
  603. {
  604. JLabel lab=(JLabel)e.getSource();
  605.  
  606. if(lab==labCards[0])
  607. {
  608. palSkill[0].setVisible(false);
  609. }
  610. if(lab==labCards[1])
  611. {
  612. palSkill[1].setVisible(false);
  613. }
  614. if(lab==labCards[2])
  615. {
  616. palSkill[2].setVisible(false);
  617. }
  618. if(lab==labCards[3])
  619. {
  620. palSkill[3].setVisible(false);
  621. }
  622. }
  623. public void mouseClicked(MouseEvent e)
  624. {
  625. JLabel lab=(JLabel)e.getSource();
  626.  
  627. if(OKClicked==false)
  628. {
  629. if(lab==labCards[0])
  630. {
  631. labCards[0].setBounds(15*1,40,150,180);
  632. if(cardChoose[0]==false)
  633. {
  634. cardChoose[0]=true;
  635. btnOK.setVisible(true);
  636. labOK.setVisible(false);
  637. }
  638. else
  639. {
  640. cardChoose[0]=false;
  641. labCards[0].setBounds(15,55,150,180);
  642. btnOK.setVisible(false);
  643. labOK.setVisible(true);
  644. }
  645.  
  646. cardChoose[1]=cardChoose[2]=cardChoose[3]=false;
  647. labCards[1].setBounds(15*2+150*1,55,150,180);
  648. labCards[2].setBounds(15*3+150*2,55,150,180);
  649. labCards[3].setBounds(15*4+150*3,55,150,180);
  650. }
  651. if(lab==labCards[1])
  652. {
  653. labCards[1].setBounds(15*2+150*1,40,150,180);
  654. if(cardChoose[1]==false)
  655. {
  656. cardChoose[1]=true;
  657. btnOK.setVisible(true);
  658. labOK.setVisible(false);
  659. }
  660. else
  661. {
  662. cardChoose[1]=false;
  663. labCards[1].setBounds(15*2+150*1,55,150,180);
  664. btnOK.setVisible(false);
  665. labOK.setVisible(true);
  666. }
  667.  
  668. cardChoose[0]=cardChoose[2]=cardChoose[3]=false;
  669. labCards[0].setBounds(15,55,150,180);
  670. labCards[2].setBounds(15*3+150*2,55,150,180);
  671. labCards[3].setBounds(15*4+150*3,55,150,180);
  672. }
  673. if(lab==labCards[2])
  674. {
  675. labCards[2].setBounds(15*3+150*2,40,150,180);
  676. if(cardChoose[2]==false)
  677. {
  678. cardChoose[2]=true;
  679. btnOK.setVisible(true);
  680. labOK.setVisible(false);
  681. }
  682. else
  683. {
  684. cardChoose[2]=false;
  685. labCards[2].setBounds(15*3+150*2,55,150,180);
  686. btnOK.setVisible(false);
  687. labOK.setVisible(true);
  688. }
  689.  
  690. cardChoose[1]=cardChoose[0]=cardChoose[3]=false;
  691. labCards[1].setBounds(15*2+150*1,55,150,180);
  692. labCards[0].setBounds(15,55,150,180);
  693. labCards[3].setBounds(15*4+150*3,55,150,180);
  694. }
  695. if(lab==labCards[3])
  696. {
  697. labCards[3].setBounds(15*4+150*3,40,150,180);
  698. if(cardChoose[3]==false)
  699. {
  700. cardChoose[3]=true;
  701. btnOK.setVisible(true);
  702. labOK.setVisible(false);
  703. }
  704. else
  705. {
  706. cardChoose[3]=false;
  707. labCards[3].setBounds(15*4+150*3,55,150,180);
  708. btnOK.setVisible(false);
  709. labOK.setVisible(true);
  710. }
  711.  
  712. cardChoose[1]=cardChoose[2]=cardChoose[0]=false;
  713. labCards[1].setBounds(15*2+150*1,55,150,180);
  714. labCards[2].setBounds(15*3+150*2,55,150,180);
  715. labCards[0].setBounds(15,55,150,180);
  716. }
  717. }
  718. }
  719. }
  720.  
  721. static class winClose extends WindowAdapter implements ActionListener //關閉視窗
  722. {
  723. public void windowClosing(WindowEvent e)
  724. {
  725. frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  726. }
  727. public void actionPerformed(ActionEvent e)
  728. {
  729. JButton btn=(JButton)e.getSource();
  730.  
  731. if(btn==btnYes)
  732. {
  733. frm.dispose();
  734. }
  735. if(btn==btnNo)
  736. {
  737. dlgExit.setVisible(false);
  738. }
  739. }
  740. }
  741. }
Add Comment
Please, Sign In to add comment