【正文】
而實現(xiàn)動作事件的監(jiān)聽。amp。 } 功能 5:鍵盤事件的 響應(yīng) 在窗體類上用 implement實現(xiàn) KeyListener接口,重寫接口所有方法,在接口的KeyPressed添加控件上、下、左、右移動的方法。 } m=n=4。 for(int i=0。 nandu3. addAction Listener(this)。 } 功能 4:難度設(shè)置 在窗體上添加菜單欄 menubar,然后在菜單欄上添加操作、設(shè)置、關(guān)于的菜單,在設(shè)置菜單中添加難度設(shè)置的菜單選項。j++) { int x1=j/n,y1=j%n。 perimage1=()+()。 功能 3:圖片選擇 通過 FileDialog df=new FileDialog (this,” 圖片選擇 ” , )。 } btn[0][0].setBackground()。i++) { pic[i]=new ImageIcon(t[i])。 //在按扭上添加事件 btn[0][i].setVisible(false)。 //添加事件 (btn[x][y])。 //下標(biāo)轉(zhuǎn)換 if(btn[x][y]==null) btn[x][y]=new JButton()。 //坐標(biāo) Image[] t=splitImage(perimage1,m,n,w,h)。 (pregtn1)。 perimagea=new ImageIcon(a[0])。 (拼圖步數(shù) :+step+步 )。 在 septic 方法中主要實現(xiàn)的功能是將圖片切割成 m 行 n 列,并存放在 pic數(shù)組中;定義數(shù)組按扭 btn[][],并且判斷控件里是否為空,如果為空則分配 m+1行 n 列的控件空間;如果存在則不分配空間這樣有助于拼圖游戲控件多少以及大小的改變。 課程設(shè)計報告 2 功能要求 ? 實現(xiàn)圖片的切割及隨機分布。 JDT 支持 Java 開發(fā)、 CDT 支持 C 開發(fā)、 PDE 用來支持插件開發(fā), Eclipse Platform 則是一個開放的可擴展 IDE,提供了一個通用的開發(fā)平臺。因此,如何設(shè)計和開發(fā)好這個拼圖游戲,對于提高 Java 開發(fā)水平和系統(tǒng)的設(shè)計能力有極大的幫助。 關(guān)鍵詞 : 拼圖游戲 Java 語言 開發(fā) The design of JAVA software based on the puzzle Abstract: Jigsaw puzzle is a very classic game, because it is easy and fun, both old and young, are more suitable. Jigsaw design language for each Java language designers to improve and advance is an excellent exercise opportunities. Puzzle design is more plex, its scope, and involves many more, if you do not think and design, would be difficult to successfully developed this game. In the design of the game involves display of the graphical interface and updating, data is collected and updated, and in the development of this game, class inheritance mechanism, and some design patterns you want to apply. Therefore, how to design and develop this jigsaw puzzle, for raising the level of Java development, and system design capabilities are of great help. During the process of design and development, you need to handle the inheritance relationships between the classes, also have to deal with each type of appropriate packaging, and also to coordinate the various logical dependencies between modules and data munication. Keywords: Jigsaw puzzle Java language develop 課程設(shè)計報告 III 目 錄 前 言 ................................................................1 開發(fā)工具介紹 ......................................................1 需求分析 ..........................................................1 開發(fā)環(huán)境與配置 ................................................1 功能要求 ......................................................2 系統(tǒng)主要功能和主要功能描述 ....................................2 關(guān)鍵技術(shù) ......................................................5 詳細(xì)設(shè)計 ..........................................................6 核心功能代碼實現(xiàn)技術(shù) ..........................................6 程序的流程圖 ..................................................7 程序運行效果圖 ................................................8 課程設(shè)計總結(jié) .....................................................10 附錄源代碼 ..........................................................11 參考文獻(xiàn) ............................................................22 課程設(shè)計報告 1 基于 JAVA 的拼圖軟件的設(shè)計 前 言 拼圖游戲一款非常經(jīng)典的小游戲,因為它比較簡單有趣,無論老少都比較適合。 拼圖游戲的設(shè)計比較復(fù)雜,它涉及面廣、牽涉方面多,如果不好好考慮和設(shè)計,將難以成功開發(fā)出這個游戲。源代碼以及可運行的拼圖程序。 ( 2)通過課程設(shè)計,開發(fā)一個小游戲,并掌握研發(fā)全程。 ( 3)通過課程設(shè)計,培養(yǎng)發(fā)現(xiàn)問題、分析問題、解決問題的能力。 具體要求: ① 設(shè)計任務(wù)與要求 ② 總體方案與說明 ③ 面向?qū)ο蟮脑O(shè)計(主要類的設(shè)計) ④ 源程序清單與注釋 ⑤ 小結(jié)與體會。在這個游戲的設(shè)計中,牽涉到圖形界面的顯示與更新、數(shù)據(jù)的收集與更新,并且在這個游戲的開發(fā)中,還要應(yīng)用類的繼承機制以及一些設(shè)計模式。拼圖的設(shè)計對每一個 Java 語言設(shè)計者進(jìn)行語言提高和進(jìn)階都是一個很好的鍛煉機會。在設(shè)計開發(fā)過程中,需要處理好各個類之間的繼承關(guān)系,還要處理各個類相應(yīng)的封裝,并且還要協(xié)調(diào)好各個模塊之間的邏輯依賴關(guān)系和數(shù)據(jù)通信關(guān)系。它提供建造塊和構(gòu)造并運行集成軟件開發(fā)工具的基礎(chǔ)。 ? 實現(xiàn)拼圖游戲的拼圖功能。將 pic中存放的圖片通過 for循環(huán)放置在 btn 控件中。 w=280/m。 if(pregtn1==null) pregtn1=new JButton(perimagea)。 pic=new ImageIcon[m*n]。 for(int i=0。 btn[x][y].setBounds(y*w+5,x*h+40,w,h)。 //在窗體上加入這些按扭 } for (int i=1。 } int temp[]=ran(m*n)。 //圖片轉(zhuǎn)換 } for (int i=0。 //設(shè)置背景顏色 課程設(shè)計報告 4 btn[0][0].setIcon(null)。這個語句實現(xiàn)圖片選擇窗口,進(jìn)行圖片選擇,將圖片的控件設(shè)為空,然后再調(diào)用 setpic 圖片放置方法將控件上的圖片進(jìn)行刷新。 if(()==null) return。 btn[x1][y1].removeActionListener(this)。 課程設(shè)計報告 5 設(shè)置三個難度,難度一 3*3為簡單,難度二 4*4為一般,難度三 5*5為偏難。 在接口方法重寫中實現(xiàn)難度設(shè)置功能,以難度 2為例,代碼如下: if(()==nandu2) { (false)。i(m+1)*n。 btn=null。通過 if語句判斷鍵盤鍵盤事件,如果按下左鍵,則是用if(y0amp。btn[x][y].getIcon()==null)語句判斷控件,如果為真,則進(jìn)行向左移動。 ? 通過對 btn 控件添加監(jiān)聽事件來實現(xiàn)拼圖游戲中的控件上下 移動 。 (80,10,120,20)。 (isover)。 (menu3)。 (item4)。 (nandu3)。 //注冊監(jiān)聽事件 (this)。 (this)。對于這種面 向?qū)ο蟮木幊趟枷耄箘側(cè)腴T的人很快就能寫出自己的程序。 ,而不是單純的寫代碼。 import 。 public class Games extends JFrame implements ActionListener { private JButton buttons[][]。// count 的作用是計算按鍵移動的次數(shù), is[]儲存一個隨機產(chǎn)生的 1到 8數(shù)字?jǐn)?shù)組 public Games() { super(拼圖游戲 )。// 將該布局方式作用于容器 buttons = new JButton[3][3]。 locate1++) {// 該方法作用是產(chǎn)生 1到 8這 8 個數(shù),隨機分配給數(shù)組,即無序排列 int g = new Random().nextInt(8) + 1。 locate2) 課程設(shè)計報告 12 { if (is[locate1] == is[locate2]) break。// 隨機產(chǎn)生一個 0到 3的數(shù),代表空白按鍵的行 int l = new Random().nextInt(3)。 j 3。 (buttons[i][j])。 } buttons[i][j].addActionListener(this)。 if (b == buttons[0][0]) { if (buttons[0][1].getText().equals(9)) { buttons[0][1].setText( + buttons[0][0].getText())。 count++。 buttons[0][0].setVisible(false)。 buttons[0][1].setText(9)。 buttons[0][2].setVisible(true)。 } else if (buttons[1][1].getText().equals(9)) { buttons[1][1].setText( + buttons[0][1].getText())。 count++。 buttons[0][2].setVisible(false)。 buttons[0][2].setText(9)。 buttons[0][0].setVisible(true)。 } else if (buttons[