JAVA纸牌游戏源代码_第1页
JAVA纸牌游戏源代码_第2页
JAVA纸牌游戏源代码_第3页
JAVA纸牌游戏源代码_第4页
JAVA纸牌游戏源代码_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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;/* * 创建日期 2005-7-10 todo 要更改此生成的文件的模板,请转至 窗口 首选项 java 代码样式 代码模板 */*download by http:/www.codefans

2、.net * author 叶少伟 todo 要更改此生成的类型注释的模板,请转至 窗口 首选项 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

3、= null;private jpanel jpanel3 = 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)

4、;owner = frame;setresizable(false);initialize();/* * this method initializes this * * return void */private void initialize()this.settitle(关于对话框);this.setsize(209, 132);this.setcontentpane(getjcontentpane();this.setlocation();this.setvisible(true);this.addwindowlistener(new java.awt.event.windowadap

5、ter() public void windowclosing(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();jcon

6、tentpane.setlayout(new 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.ge

7、theight();int x = (int) (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 getjtabbedpan

8、e() if (jtabbedpane = null) jtabbedpane = new jtabbedpane();jtabbedpane.addtab(关于, null, getjpanel(), null);jtabbedpane.addtab(作者, null, getjpanel1(), null);jtabbedpane.addtab(班级, null, getjpanel2(), null);jtabbedpane.addtab(学号, null, getjpanel3(), null);return jtabbedpane;/* * this method initializ

9、es jpanel * * return javax.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 jpane

10、l;/* * this method initializes 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);j

11、panel1.add(jlabel1, null);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计算机(1)班);jlabel2.setforeground(java.awt.color.blue);jlabel2.setfont(new java

12、.awt.font(楷体_gb2312, java.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(

13、java.awt.color.blue);jlabel3.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(), n

14、ull);return jpanel4;/* * 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

15、 e) owner.setenabled(true);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.*;/* * 创建日期 2005-7-12 todo 要更改此生成的文件的模板,请转至 窗口 首选项 java 代码样式 代码模板 */*download by http:/www.

16、 * author 叶少伟 todo 要更改此生成的类型注释的模板,请转至 窗口 首选项 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

17、 = new pkcard104; private jlabel clicklabel = 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 *

18、/ public araneid() super(); this.setdefaultcloseoperation(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()

19、; this.clicklabel.setbounds(883, 606, 121, 96); 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(); groundlabe

20、l = new jlabel10; int x = 20; for (int i = 0; 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); thi

21、s.deal(); this.addkeylistener(new keyadapter() 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(

22、); ); public void newgame() this.randomcards(); 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

23、 (this.grade = araneid.easy) n = 1; else if (this.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 5

24、2; i+) int a = (int) (math.random() * 104); int 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+

25、) for (int j = 0; j 5; i-) for (int j = 0; j = 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

26、(point != null) n+; point = this.getlastcardlocation(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

27、).iscardcanmove() card = this.getpreviouscard(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)

28、 break out; c = (pkcard) this.table.get(p); while (!c.iscardcanmove(); if (c.getcardvalue() = card.getcardvalue() + 1) card.flashcard(card); try thread.sleep(800); catch (interruptedexception e) / todo 自动生成 catch 块 e.printstacktrace(); c.flashcard(c); a+; if (a = 10) n+; break out; n+; if (n = 10) n

29、 = 0; x+; if (x = 10) break out; public void deal() this.setna(); for (int i = 0; i 10; i+) if (this.getlastcardlocation(i) = null) joptionpane.showmessagedialog(this, 有空位不能发牌!, 提示, joptionpane.warning_message); return; int x = 20; for (int i = 0; i 10; i+) point lastpoint = this.getlastcardlocation

30、(i); if (c = 0) lastpoint.y += 5; else lastpoint.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(lastpo

31、int); if (cardsc + i.getcardvalue() = 1) int n = 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(car

32、d.getlocation(); point.y -= 5; card = (pkcard) 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 !=

33、 null) return card; point.y += 15; card = (pkcard) 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();

34、card = this.getnextcard(card); return point; public 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 =

35、 this.getlastcardlocation(column); pkcard card = (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

36、 (point = null) card = null; else card = (pkcard) this.table.get(point); while (card != null & card.iscardcanmove(); finish+; if (finish = 8) joptionpane.showmessagedialog(this, 恭喜你,过关了!, 成功, joptionpane.plain_message); if (card != null) card.turnfront(); card.setcanmove(true); araneidmenubar.java程序

37、import javax.swing.jmenubar;import javax.swing.jmenu;import javax.swing.jmenuitem;import javax.swing.jradiobuttonmenuitem;import javax.swing.buttongroup;/* * 创建日期 2005-7-14 todo 要更改此生成的文件的模板,请转至 窗口 首选项 java 代码样式 代码模板 */*download by * author 叶少伟 todo 要更改此生成的类型注释的模板,请转至 窗口 首选项 j

38、ava 代码样式 代码模板 */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 = nu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论