第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JAVA窗體中2個小球怎樣能互不干涉反彈移動?

JAVA窗體中2個小球怎樣能互不干涉反彈移動?

瑾色羊 2018-03-20 19:57:33
這段代碼運(yùn)行后,兩小球距離總是恒定,怎樣讓他們兩個是各自獨(dú)立,有各自的軌跡?import java.awt.*;public class Rebound{ public static void main(String args[]) { Frame w=new Frame(); w.setSize(800, 800); MyRebound mp=new MyRebound(); w.add(mp);? ? ? ? ? ? ?Thread t=new Thread(mp); ? ? ? t.start(); ? ? ?? ? ? ?w.show(); ? ? ? ? ? ? ? ? }}class MyRebound extends Panel implements Runnable{ ? ? ?int x=(int)(Math.random()*800);? ? ? ?int y=(int)(Math.random()*800); ? ? ?int i=(int)(Math.random()*800); ? ? ?int j=(int)(Math.random()*800); ? ? ?int att=0; public void paint(Graphics g) { g.fillOval(x, y, 50, 50);? g.setColor(Color.yellow); g.fillOval(i, j, 50, 50); } public void run(){ ? ? ? while(true) { ? ? ? //定義飛行姿態(tài) ? ? ? if(att==0) { ? ? ? x++; ?? ? ? ? y++; ? ? ? i++; ? ? ?j++; ? ? ? } ? ? ? if(att==1) { ? ? ? x--; ? ? ? y++; ? ? ? i--; ? ? ? j++; ? ? ? } ? ? ? if(att==2) { ? ? ? x--; ? ? ? y--; ? ? ? i--; ? ? ? j--; ? ? ? } ? ? ? if(att==3) { ? ? ? x++; ? ? ? y--; ? ? ? i++; ? ? ? j--; ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ?//改變飛行姿態(tài) ? ? ? ? ? ?if(x>730) { ? ? ? ? ? ?if (att==0) { ? ? ? ? ? ? att=1; ? ? ? ? ? ?}else { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? att=2; ? ? ? ?} ?} ? ? ? ? ? ? ? ? ? ? ?if(y>700) { ? ? ? ? ?if(att==1) { ? ? ? ? ?att=2; ? ? ? ? ?}else { ? ? ? ? ?att=3; ? ? ? ? ?} ? ? ? ? ?} ? ? ? ? ?if(x<0) { ? ? ? ? ?if(att==2) { ? ? ? ? ?att=3; ? ? ? ? ?}else { ? ? ? ? ?att=0; ? ? ? ? ?} ? ? ? ? ?} ? ? ? ? ?if(y<0) { ? ? ? ? ?if(att==3) { ? ? ? ? ?att=0; ? ? ? ? ?}else { ? ? ? ? ?att=1; ? ? ? ? ?} ? ? ? ? ?}?//......................................................................................... ? ? ? ? ?if(i>730) { ? ? ? ? ? ?if (att==0) { ? ? ? ? ? ? att=1; ? ? ? ? ? ?}else { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? att=2; ? ? ? ?} ?} ? ? ? ? ? ? ? ? ? ? ?if(j>700) { ? ? ? ? ?if(att==1) { ? ? ? ? ?att=2; ? ? ? ? ?}else { ? ? ? ? ?att=3; ? ? ? ? ?} ? ? ? ? ?} ? ? ? ? ?if(i<0) { ? ? ? ? ?if(att==2) { ? ? ? ? ?att=3; ? ? ? ? ?}else { ? ? ? ? ?att=0; ? ? ? ? ?} ? ? ? ? ?} ? ? ? ? ?if(j<0) { ? ? ? ? ?if(att==3) { ? ? ? ? ?att=0; ? ? ? ? ?}else { ? ? ? ? ?att=1; ? ? ? ? ?} ? ? ? ? ?} ? ? ? ? ?try { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Thread.sleep(5); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //線程休眠5毫秒 ? ? ? }catch(Exception e) {} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//異常處理 ? ? ? ? repaint(); ? ? ? ? } ?? }}
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 1123 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號