資源簡介
設計GUI(Graphical User Interface)界面的動物換位游戲,游戲的結果是讓左右兩組動物交換位置。具體要求如下:
1.程序分為3個級別,用戶通過菜單來選擇初級、中級和高級。對于初級,在水平排列的7塊石頭上的左右各有3個類型相同的動物,中間的石頭上沒有動物;對于中級,在水平排列的 塊石頭上的左右各有4個類型相同的動物,中間的石頭上沒有動物;對于高級,在水平排列的11塊石頭上左右各有5個類型相同的動物,中間的石頭上沒有動物。
2.用鼠標單擊一個動物,如果該動物前方的石頭上沒有動物,該動物跳躍到該石頭上,如果該動物前方的石頭上有其他動物,但隔位上的石頭沒有動物,該動物就越過自己前面的動物跳躍到石頭上,其他情形時,該動物不跳躍(跳躍時不能越過2塊石頭)。
3.左面的動物只能向右方跳躍,右面的動物只能向左方跳躍。
4.用戶可以通過界面提供的按鈕,讓程序自動完成動物換位。
5.可以隨時重新開始不同的級別。
6.用戶通過菜單選項,可以選擇左、右動物的圖像。

代碼片段和文件信息
/*
?*?設置動物屬性:
?*?動物所在的point
?*?動物圖片路徑
?*?動物是否在左邊
?*/
import?javax.swing.*;
import?java.awt.*;
import?java.io.*;
public?class?Animal?extends?JPanel
{
???Point?point;?//
???
???boolean?isLeft;//是否在左邊
???
???Toolkit?tool;//
//???This?class?is?the?abstract?superclass?of?all?actual?implementations?of?the?Abstract?Window?Toolkit.?
//???Subclasses?of?the?Toolkit?class?are?used?to?bind?the?various?components?to?particular?native?toolkit?implementations.?
//
//???Many?GUI?events?may?be?delivered?to?user?asynchronously?if?the?opposite?is?not?specified?explicitly.?
//???As?well?as?many?GUI?operations?may?be?performed?asynchronously.?This?fact?means?that?if?the?state?of?a?component?is?set
//???and?then?the?state?immediately?queried?the?returned?value?may?not?yet?reflect?the?requested?change.?
//???This?behavior?includes?but?is?not?limited?to:?
//
//???Scrolling?to?a?specified?position.?
//???For?example?calling?ScrollPane.setScrollPosition?and?then?getScrollPosition?may?return?an?incorrect?value?if?the?original?request?has?not?yet?been?processed.?
//
//???Moving?the?focus?from?one?component?to?another.?
//???For?more?information?see?Timing?Focus?Transfers?a?section?in?The?Swing?Tutorial.?
//
//???Making?a?top-level?container?visible.?
//???Calling?setVisible(true)?on?a?Window?frame?or?Dialog?may?occur?asynchronously.?
//
//???Setting?the?size?or?location?of?a?top-level?container.?
//???Calls?to?setSize?setBounds?or?setLocation?on?a?Window?frame?or?Dialog?are?forwarded?to?the?underlying?window?management?system
//???and?may?be?ignored?or?modified.?See?java.awt.Window?for?more?information.?
//???Most?applications?should?not?call?any?of?the?methods?in?this?class?directly.?The?methods?defined?by?Toolkit?are?the?“glue“?that?
//???joins?the?platform-independent?classes?in?the?java.awt?package?with?their?counterparts?in?java.awt.peer.?
//???Some?methods?defined?by?Toolkit?query?the?native?operating?system?directly.
//???實現功能
//???1、滾動到指定位置
//???例如,如果原始請求沒有被處理,那么調用?ScrollPane.setScrollPosition?并隨后調用?getScrollPosition?可能返回一個不正確的值。
//???2、將焦點從一個組件移動到另一個組件。
//???3、使某一頂層容器可視。
//???4、設置頂層容器的大小或位置
//???因為是抽象類,所以不能用new?實例化,可以用getDefaultToolkit返回Toolkit類的對象
//???例如:?Toolkit?toolkit=Toolkit.getDefaultToolkit();
???
???File?leftImage;?//左圖片文件
???File?rightImage;//右圖片文件
???
???Animal()
???{
???????tool=getToolkit();
//???????Gets?the?toolkit?of?this?component.?Note?that?the?frame?that?contains?a?component
//???????controls?which?toolkit?is?used?by?that?component.?Therefore?if?the?component?is?moved
//???????from?one?frame?to?another?the?toolkit?it?uses?may?change.
//???????對系統低層實現圖形控件的最基本功能的一些接口
???}
???public?void?setLeftImage(File?f)//設置左邊的動物
???{
???????leftImage=f;
???}
?
???public?void?setRightImage(File?f)//設置右邊的動物
???{
???????rightImage=f;
???}
???public?void?setIsLeft(boolean?boo)//設置是否為左邊的動物
???{
???????isLeft=boo;
???}
???public?boolean??getIsLeft()//判斷是否為左邊的動物
???{
???????return?isLeft;
???}
???public?void?setAtPoint(Point?p)//設置此時在哪個point
???{
??????po
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.???????295??2014-12-23?19:31??AnimalChange\.classpath
????..A..H.??????8196??2014-12-25?11:39??AnimalChange\.DS_Store
????..A..H.???????371??2014-12-23?19:31??AnimalChange\.project
?????文件?????????76??2015-01-05?12:00??AnimalChange\.settings\org.eclipse.core.resources.prefs
?????文件????????587??2014-12-23?19:31??AnimalChange\.settings\org.eclipse.jdt.core.prefs
????..A..H.??????6148??2014-12-23?20:34??AnimalChange\bin\.DS_Store
?????文件???????1899??2015-01-08?09:31??AnimalChange\bin\Animal.class
?????文件????????987??2015-01-09?11:08??AnimalChange\bin\AutoMoveAnimal$1.class
?????文件???????6935??2015-01-09?11:08??AnimalChange\bin\AutoMoveAnimal.class
?????文件????????789??2015-01-09?11:17??AnimalChange\bin\ChangeAnimalWindow$1.class
?????文件??????13013??2015-01-09?11:17??AnimalChange\bin\ChangeAnimalWindow.class
?????文件????????649??2015-01-08?09:31??AnimalChange\bin\Customdlg$1.class
?????文件???????2064??2015-01-08?09:31??AnimalChange\bin\Customdlg.class
?????文件???????5860??2015-01-08?11:17??AnimalChange\bin\HandleMouse.class
?????文件????????846??2015-01-09?09:29??AnimalChange\bin\People.class
?????文件???????1346??2015-01-08?09:31??AnimalChange\bin\Point.class
?????文件???????2971??2015-01-08?09:31??AnimalChange\bin\Record.class
?????文件????????645??2015-01-08?11:06??AnimalChange\bin\ShowRecordDialog$1.class
?????文件???????3907??2015-01-08?11:06??AnimalChange\bin\ShowRecordDialog.class
?????文件????????454??2015-01-08?09:31??AnimalChange\bin\Stone.class
????..A..H.??????6148??2015-01-05?19:56??AnimalChange\images\.DS_Store
?????文件??????11384??2015-01-05?12:18??AnimalChange\images\cat.JPG
?????文件???????4793??2015-01-05?11:53??AnimalChange\images\cat10.jpg
?????文件???????4297??2015-01-05?11:51??AnimalChange\images\cat2.jpg
?????文件???????4522??2015-01-05?11:51??AnimalChange\images\cat3.jpg
?????文件???????4993??2015-01-05?11:51??AnimalChange\images\cat4.jpg
?????文件???????4401??2015-01-05?11:51??AnimalChange\images\cat5.jpg
?????文件???????8570??2015-01-05?11:52??AnimalChange\images\cat6.jpg
?????文件???????5074??2015-01-05?11:52??AnimalChange\images\cat7.jpg
?????文件???????7384??2015-01-05?11:52??AnimalChange\images\cat8.jpg
............此處省略40個文件信息
- 上一篇:android繪制心電圖
- 下一篇:Android雙列滑動表格(雙表頭不動)
評論
共有 條評論