JAVA紙牌游戲源代碼_第1頁
JAVA紙牌游戲源代碼_第2頁
JAVA紙牌游戲源代碼_第3頁
JAVA紙牌游戲源代碼_第4頁
JAVA紙牌游戲源代碼_第5頁
已閱讀5頁,還剩25頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、aboutdialog.java程序import javax.swing.jdialog;import javax.swing.jframe;import java.awt.point;import javax.swing.jtabbedpane;import javax.swing.jpanel;import javax.swing.jbutton;import javax.swing.jlabel;/* * 創(chuàng)建日期 2005-7-10 todo 要更改此生成的文件的模板,請轉(zhuǎn)至 窗口 首選項(xiàng) java 代碼樣式 代碼模板 */*download by * author 葉少偉 todo

2、要更改此生成的類型注釋的模板,請轉(zhuǎn)至 窗口 首選項(xiàng) java 代碼樣式 代碼模板 */public class aboutdialog extends jdialogprivate javax.swing.jpaneljcontentpane= null;protected jframeowner= null;private jtabbedpane jtabbedpane = null;private jpanel jpanel = null;private jpanel jpanel1 = null;private jpanel jpanel2 = null;private jpanel j

3、panel3 = null;private jpanel jpanel4 = null;private jbutton jbutton = null;private jlabel jlabel = null;private jlabel jlabel1 = null;private jlabel jlabel2 = null;private jlabel jlabel3 = null;/* * this is the default constructor */public aboutdialog(jframe frame)super(frame);owner = frame;setresiz

4、able(false);initialize();/* * this method initializes this * * return void */private void initialize()this.settitle(關(guān)于對話框);this.setsize(209, 132);this.setcontentpane(getjcontentpane();this.setlocation();this.setvisible(true);this.addwindowlistener(new java.awt.event.windowadapter() public void windo

5、wclosing(java.awt.event.windowevent e) owner.setenabled(true);aboutdialog.this.dispose(););/* * this method initializes jcontentpane * * return javax.swing.jpanel */private javax.swing.jpanel getjcontentpane()if (jcontentpane = null)jcontentpane = new javax.swing.jpanel();jcontentpane.setlayout(new

6、java.awt.borderlayout();jcontentpane.add(getjtabbedpane(), java.awt.borderlayout.center);jcontentpane.add(getjpanel4(), java.awt.borderlayout.south);return jcontentpane;private void setlocation()point point = owner.getlocation();int width = this.getwidth();int height = this.getheight();int x = (int)

7、 (point.getx() + (owner.getwidth() - width) / 2);x = (x 1024 - width ? 1024 - width : x);x = (x 768 - height ? 768 - height : y);y = (y 0 ? 0 : y);setlocation(x, y);/* * this method initializes jtabbedpane * * return javax.swing.jtabbedpane */ private jtabbedpane getjtabbedpane() if (jtabbedpane = n

8、ull) jtabbedpane = new jtabbedpane();jtabbedpane.addtab(關(guān)于, null, getjpanel(), null);jtabbedpane.addtab(作者, null, getjpanel1(), null);jtabbedpane.addtab(班級(jí), null, getjpanel2(), null);jtabbedpane.addtab(學(xué)號(hào), null, getjpanel3(), null);return jtabbedpane;/* * this method initializes jpanel * * return ja

9、vax.swing.jpanel */ private jpanel getjpanel() if (jpanel = null) jlabel = new jlabel();jpanel = new jpanel();jlabel.settext(蜘蛛牌);jlabel.setfont(new java.awt.font(楷體_gb2312, java.awt.font.bold, 18);jlabel.setforeground(java.awt.color.blue);jpanel.add(jlabel, null);return jpanel;/* * this method init

10、ializes jpanel1 * * return javax.swing.jpanel */ private jpanel getjpanel1() if (jpanel1 = null) jlabel1 = new jlabel();jpanel1 = new jpanel();jlabel1.settext(葉少偉);jlabel1.setfont(new java.awt.font(楷體_gb2312, java.awt.font.bold, 18);jlabel1.setforeground(java.awt.color.blue);jpanel1.add(jlabel1, nul

11、l);return jpanel1;/* * this method initializes jpanel2 * * return javax.swing.jpanel */ private jpanel getjpanel2() if (jpanel2 = null) jlabel2 = new jlabel();jpanel2 = new jpanel();jlabel2.settext(a02計(jì)算機(jī)(1)班);jlabel2.setforeground(java.awt.color.blue);jlabel2.setfont(new java.awt.font(楷體_gb2312, ja

12、va.awt.font.bold, 18);jpanel2.add(jlabel2, null);return jpanel2;/* * this method initializes jpanel3 * * return javax.swing.jpanel */ private jpanel getjpanel3() if (jpanel3 = null) jlabel3 = new jlabel();jpanel3 = new jpanel();jlabel3.settext(020505101);jlabel3.setforeground(java.awt.color.blue);jl

13、abel3.setfont(new java.awt.font(楷體_gb2312, java.awt.font.bold, 18);jpanel3.add(jlabel3, null);return jpanel3;/* * this method initializes jpanel4 * * return javax.swing.jpanel */ private jpanel getjpanel4() if (jpanel4 = null) jpanel4 = new jpanel();jpanel4.add(getjbutton(), null);return jpanel4;/*

14、* this method initializes jbutton * * return javax.swing.jbutton */ private jbutton getjbutton() if (jbutton = null) jbutton = new jbutton();jbutton.settext(確定);jbutton.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) owner.setenabled(tr

15、ue);aboutdialog.this.dispose(););return jbutton; / jve:decl-index=0:visual-constraint=10,10 araneid.java程序import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;/* * 創(chuàng)建日期 2005-7-12 todo 要更改此生成的文件的模板,請轉(zhuǎn)至 窗口 首選項(xiàng) java 代碼樣式 代碼模板 */*download by * author 葉少偉 todo 要更改此生成的類型注釋的模板,

16、請轉(zhuǎn)至 窗口 首選項(xiàng) java 代碼樣式 代碼模板 */public class araneid extends jframe public static final int easy = 1; public static final int natural = 2; public static final int hard = 3; private int grade = araneid.easy; private container pane = null; private pkcard cards = new pkcard104; private jlabel clicklabel =

17、null; private int c = 0; private int n = 0; private int a = 0; private int finish = 0; hashtable table = null; private jlabel groundlabel = null; public static void main(string args) araneid araneid = new araneid(); /* * this is the default constructor */ public araneid() super(); this.setdefaultclo

18、seoperation(javax.swing.jframe.exit_on_close); this.setsize(1024, 742); this.setjmenubar(new araneidmenubar(this); this.pane = this.getcontentpane(); this.pane.setbackground(new color(0, 112, 26); this.pane.setlayout(null); this.clicklabel = new jlabel(); this.clicklabel.setbounds(883, 606, 121, 96)

19、; this.pane.add(this.clicklabel); this.clicklabel.addmouselistener(new mouseadapter() public void mousereleased(mouseevent me) if (c 60) araneid.this.deal(); ); this.settitle(蜘蛛牌); this.initcards(); this.randomcards(); this.setcardslocation(); groundlabel = new jlabel10; int x = 20; for (int i = 0;

20、i 10; i+) groundlabeli = new jlabel(); groundlabeli .setborder(javax.swing.borderfactory .createetchedborder(javax.swing.border.etchedborder.raised); groundlabeli.setbounds(x, 25, 71, 96); x += 101; this.pane.add(groundlabeli); this.setvisible(true); this.deal(); this.addkeylistener(new keyadapter()

21、 class show extends thread public void run() araneid.this.showenableoperator(); public void keypressed(keyevent e) if (finish != 8) if (e.getkeycode() = keyevent.vk_d & c 60) araneid.this.deal(); else if (e.getkeycode() = keyevent.vk_m) new show().start(); ); public void newgame() this.randomcards()

22、; this.setcardslocation(); this.setgroundlabelzorder(); this.deal(); public int getc() return c; public void setgrade(int grade) this.grade = grade; public void initcards() if (cards0 != null) for (int i = 0; i 104; i+) pane.remove(cardsi); int n = 0; if (this.grade = araneid.easy) n = 1; else if (t

23、his.grade = araneid.natural) n = 2; else n = 4; for (int i = 1; i = 8; i+) for (int j = 1; j = 13; j+) cards(i - 1) * 13 + j - 1 = new pkcard(i % n + 1) + - + j, this); this.randomcards(); public void randomcards() pkcard temp = null; for (int i = 0; i 52; i+) int a = (int) (math.random() * 104); in

24、t b = (int) (math.random() * 104); temp = cardsa; cardsa = cardsb; cardsb = temp; public void setna() a = 0; n = 0; public void setcardslocation() table = new hashtable(); c = 0; finish = 0; n = 0; a = 0; int x = 883; int y = 580; for (int i = 0; i 6; i+) for (int j = 0; j 5; i-) for (int j = 0; j =

25、 104) continue; pane.add(cardsn); cardsn.turnrear(); cardsn.moveto(new point(x, y); table.put(new point(x, y), cardsn); x += 101; x = 20; y -= 5; public void showenableoperator() int x = 0; out: while (true) point point = null; pkcard card = null; do if (point != null) n+; point = this.getlastcardlo

26、cation(n); while (point = null) point = this.getlastcardlocation(+n); if (n = 10) n = 0; x+; if (x = 10) break out; card = (pkcard) this.table.get(point); while (!card.iscardcanmove(); while (this.getpreviouscard(card) != null & this.getpreviouscard(card).iscardcanmove() card = this.getpreviouscard(

27、card); if (a = 10) a = 0; for (; a 10; a+) if (a != n) point p = null; pkcard c = null; do if (p != null) a+; p = this.getlastcardlocation(a); int z = 0; while (p = null) p = this.getlastcardlocation(+a); if (a = 10) a = 0; if (a = n) a+; z+; if (z = 10) break out; c = (pkcard) this.table.get(p); wh

28、ile (!c.iscardcanmove(); if (c.getcardvalue() = card.getcardvalue() + 1) card.flashcard(card); try thread.sleep(800); catch (interruptedexception e) / todo 自動(dòng)生成 catch 塊 e.printstacktrace(); c.flashcard(c); a+; if (a = 10) n+; break out; n+; if (n = 10) n = 0; x+; if (x = 10) break out; public void d

29、eal() this.setna(); for (int i = 0; i 10; i+) if (this.getlastcardlocation(i) = null) joptionpane.showmessagedialog(this, 有空位不能發(fā)牌!, 提示, joptionpane.warning_message); return; int x = 20; for (int i = 0; i 10; i+) point lastpoint = this.getlastcardlocation(i); if (c = 0) lastpoint.y += 5; else lastpoi

30、nt.y += 20; table.remove(cardsc + i.getlocation(); cardsc + i.moveto(lastpoint); table.put(new point(lastpoint), cardsc + i); cardsc + i.turnfront(); cardsc + i.setcanmove(true); this.pane.setcomponentzorder(cardsc + i, 1); point point = new point(lastpoint); if (cardsc + i.getcardvalue() = 1) int n

31、 = cardsc + i.whichcolumnavailable(point); point.y -= 240; pkcard card = (pkcard) this.table.get(point); if (card != null & card.iscardcanmove() this.havefinish(n); x += 101; c += 10; public pkcard getpreviouscard(pkcard card) point point = new point(card.getlocation(); point.y -= 5; card = (pkcard)

32、 table.get(point); if (card != null) return card; point.y -= 15; card = (pkcard) table.get(point); return card; public pkcard getnextcard(pkcard card) point point = new point(card.getlocation(); point.y += 5; card = (pkcard) table.get(point); if (card != null) return card; point.y += 15; card = (pkc

33、ard) table.get(point); return card; public point getlastcardlocation(int column) point point = new point(20 + column * 101, 25); pkcard card = (pkcard) this.table.get(point); if (card = null) return null; while (card != null) point = card.getlocation(); card = this.getnextcard(card); return point; p

34、ublic point getgroundlabellocation(int column) return new point(groundlabelcolumn.getlocation(); public void setgroundlabelzorder() for (int i = 0; i 10; i+) pane.setcomponentzorder(groundlabeli, 105 + i); public void havefinish(int column) point point = this.getlastcardlocation(column); pkcard card

35、 = (pkcard) this.table.get(point); do this.table.remove(point); card.moveto(new point(20 + finish * 10, 580); pane.setcomponentzorder(card, 1); this.table.put(card.getlocation(), card); card.setcanmove(false); point = this.getlastcardlocation(column); if (point = null) card = null; else card = (pkca

36、rd) this.table.get(point); while (card != null & card.iscardcanmove(); finish+; if (finish = 8) joptionpane.showmessagedialog(this, 恭喜你,過關(guān)了!, 成功, joptionpane.plain_message); if (card != null) card.turnfront(); card.setcanmove(true); araneidmenubar.java程序import javax.swing.jmenubar;import javax.swing

37、.jmenu;import javax.swing.jmenuitem;import javax.swing.jradiobuttonmenuitem;import javax.swing.buttongroup;/* * 創(chuàng)建日期 2005-7-14 todo 要更改此生成的文件的模板,請轉(zhuǎn)至 窗口 首選項(xiàng) java 代碼樣式 代碼模板 */*download by * author 葉少偉 todo 要更改此生成的類型注釋的模板,請轉(zhuǎn)至 窗口 首選項(xiàng) java 代碼樣式 代碼模板 */public class araneidmenubar extends jmenubar private araneid main = null; private jmenu jmenu = null; private jmenu jmenu1 = null; private jmenuitem jmenuitem = null; private jmenuitem jmenuitem1 = null; private jmenuitem jmenuitem2 = null; private jradiobuttonmenuitem jradiobuttonmenuitem = null; pri

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論