我有多個文件和類。簡單地說,人們將計算一個粒子的位置,而另一個粒子移動粒子。我遇到的問題是在第一堂課完成計算之前,粒子正在移動。我試着讓兩種方法同步,但似乎沒有什麼不同,是因爲它們在不同的類中?什麼是最好的方法來做到這一點?如何在不同的類和文件中創建同步的方法?
編輯:我沒有使用線程,它似乎並行運行多個方法。
編輯2:這裏是我的代碼
MovingParticle.java
public int x, y;
public void shootParticle(){
//move particle and change x, y values
//this method is called by a timer
}
public void drawParticle(){
//draws the particle
}
第二個文件的概要
AllOtherParticles.java
public void checkIfTheyCollide(){
for(run through arrayList){
//check if it collides with each point in array
}
public void drawCluster(){
//draws the cluster
}
同步(TheParticle){...} – Erik 2011-04-03 22:59:54
埃裏克,這應該是一個答案,所以我可以給予好評它:-) – meriton 2011-04-03 23:01:54
有一個bug在你的代碼中,發佈代碼。 – ThomasRS 2011-04-03 23:17:57