版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、package com.hadeslee.apple.client;import java.awt.borderlayout;import java.awt.color;import java.awt.dimension;import java.awt.graphics;import java.awt.graphics2d;import java.awt.event.mouseevent;import java.awt.event.mouselistener;import javax.swing.jframe;import javax.swing.jpanel;public class tes
2、t extends jframe/* serial */private static final long serialversionuid = 1l;boolean mousetag = false;boolean crosstag = false;int epointx = 0;int epointy = 0;int type = 0;int xdir = 10;int xdir1 = 21;int ydir1 = 113;int xdir2 = 10;int ydir2 = 110;jpanel panel = null;jpanel carpanel = null;thread dra
3、wthread = null;thread carthread = null;public test()panel = new jpanel()/* serial */private static final long serialversionuid = 1l;overridepublic void paint(graphics g)super.paint(g);graphics2d g2 = (graphics2d) g;g2.drawstring(你是我的小龜!, 200, 20);/ 十字路口g2.drawline(138, 0, 138, 90);g2.drawline(0, 90,
4、 138, 90);g2.drawline(0, 150, 138, 150);g2.drawline(138, 150, 138, 270);g2.drawline(330, 0, 330, 90);g2.drawline(330, 90, 490, 90);g2.drawline(330, 150, 330, 270);g2.drawline(330, 150, 490, 150);switch (type)case 0:g2.setcolor(color.red);g2.fillroundrect(10, 10, 22, 22, 90, 90);g2.setcolor(color.gre
5、en);g2.fillroundrect(10, 35, 22, 22, 90, 90);g2.setcolor(color.yellow);g2.fillroundrect(10, 60, 22, 22, 90, 90);break;case 1:g2.setcolor(color.green);g2.fillroundrect(10, 10, 22, 22, 90, 90);g2.setcolor(color.red);g2.fillroundrect(10, 35, 22, 22, 90, 90);g2.setcolor(color.yellow);g2.fillroundrect(10
6、, 60, 22, 22, 90, 90);break;case 2:g2.setcolor(color.green);g2.fillroundrect(10, 10, 22, 22, 90, 90);g2.setcolor(color.yellow);g2.fillroundrect(10, 35, 22, 22, 90, 90);g2.setcolor(color.red);g2.fillroundrect(10, 60, 22, 22, 90, 90);break;default:break;/ carg2.setcolor(color.green);g2.filloval(xdir1,
7、 ydir1, 8, 8);g2.setcolor(color.black);g2.filloval(xdir2, ydir2, 12, 12);/ mouse roundif (mousetag)g2.setcolor(color.red);g2.drawoval(epointx - 12, epointy - 35, 20, 20);g2.drawline(xdir1 + xdir2) / 2 + 6, (ydir2 + 6),epointx - 6, epointy - 25);xdir1 = (xdir1 + xdir2) / 2 + 6;ydir1 = (ydir1 + 6);if
8、(crosstag)g2.setcolor(color.red);g2.drawstring(哎喲!, xdir1, ydir1);drawthread = new thread()overridepublic void run()while (true)trythread.sleep(1000);if (type = 0)type = 1;else if (type = 1)type = 2;else if (type = 2)type = 0;panel.repaint(0, 0, 50, 100);catch (interruptedexception e)e.printstacktra
9、ce();add(panel, borderlayout.center);if (drawthread.getstate() = thread.state.runnable)return;elsedrawthread.start();/ /carthread = new thread()overridepublic void run()while (true)try/ 自由開,遇到障礙物拐彎freeruncar();thread.sleep(50);repaint();catch (interruptedexception e)private void freeruncar()/ 前進方向if
10、 (epointx xdir2)xdir1 = xdir2 + 8;if (xdir2 480)xdir2 = 0;xdir2 += 1;else if (epointx 480)xdir2 = 0;xdir2 -= 1;else if (epointx = xdir2)xdir1 = xdir2;if (xdir2 480)xdir2 = 0;xdir2 -= 1;if (epointy - 25 ydir2)ydir1 = ydir2 + 8;if (ydir2 330)ydir2 = 0;ydir2 += 1;else if (epointy - 25 330)ydir2 = 0;ydi
11、r2 -= 1;else if (epointy - 25 = ydir2)ydir1 = ydir2;if (ydir2 330)ydir2 = 0;ydir2 -= 1;/ 碰撞檢測 138, 90/ 138, 150/330, 90/330, 150if (xdir1 = 138 & ydir1 = 90)crosstag = true;else if (xdir1 = 150)crosstag = true;else if (xdir1 = 330 & ydir1 = 330 & ydir1 = 150)crosstag = true;elsecrosstag = false;if (
12、crosstag)epointx = 250;if (carthread.getstate() = thread.state.runnable)return;elsecarthread.start();/ 鼠標threadfinal thread mousethread = new thread()overridepublic void run()while (true)if (mousetag)overridepublic void interrupt()mousetag = false;if (mousethread.getstate() = thread.state.runnable)r
13、eturn;elsemousethread.start();this.addmouselistener(new mouselistener()overridepublic void mouseclicked(mouseevent e)/ system.out.println(e.getx() + , + e.gety();overridepublic void mousereleased(mouseevent e)epointx = e.getpoint().x;epointy = e.getpoint().y;mousetag = false;overridepublic void mousepressed(mouseevent e)epointx = e.getpoint().x;epointy = e.getpoint().y;mousetag = true;overridepublic void mouseexited(mouseevent e)overridepublic void mouseentered(mouseevent e);public static
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年大學(xué)大一(建筑施工技術(shù))施工工藝期中測試試題及答案
- 2025年中職生物(動物學(xué)基礎(chǔ))試題及答案
- 2025年大學(xué)大一(動物科學(xué))動物遺傳學(xué)綜合測試題及答案
- 2025年大學(xué)大一(文化產(chǎn)業(yè)管理)文化市場階段測試試題及答案
- 2025年中職種子生產(chǎn)技術(shù)(良種選育)試題及答案
- 2025年大學(xué)生物(生物多樣性保護)試題及答案
- 2025年大學(xué)生態(tài)學(xué)(生態(tài)環(huán)境基礎(chǔ))試題及答案
- 2025年大學(xué)化學(xué)(無機化學(xué))試題及答案
- 2025年大學(xué)體育(網(wǎng)球教學(xué))試題及答案
- 2026年黑龍江農(nóng)墾職業(yè)學(xué)院單招職業(yè)技能考試模擬試題帶答案解析
- 2025年國資委主任年終述職報告
- 大學(xué)教學(xué)督導(dǎo)與課堂質(zhì)量監(jiān)控工作心得體會(3篇)
- 2025年下半年國家教師資格幼兒園《綜合素質(zhì)》考試真題及參考答案
- 項目專家評審意見書標準模板
- 評審委托協(xié)議書
- 黑龍江中醫(yī)藥大學(xué)《無機化學(xué)》2025 學(xué)年第二學(xué)期期末試卷
- 2025年高中計算機操作試題題庫及答案
- 研學(xué)基地課程書籍或課件
- 杭州市西湖區(qū)人民政府西溪街道辦事處公開招聘編外合同制工作人員5人考試筆試備考試題及答案解析
- 2026年山西信息職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫及參考答案詳解1套
- 【《四川省鶴林中學(xué)學(xué)生宿舍樓施工組織設(shè)計》12000字】
評論
0/150
提交評論