Note that there are some explanatory texts on larger screens.

plurals
  1. POChange an image, according to the situation
    primarykey
    data
    text
    <p>I am working on a class project it's a flight radar simulator.</p> <p>The situation is that when 2 planes are dangerously close the image of both flights changes, and when they are in a safe distance they change again.</p> <p><img src="https://i.stack.imgur.com/RiT7U.jpg" alt="Radar" title="Radar"></p> <p>The problem is that most of the time only one of those images is changed to red and I have no idea where the problem could be.</p> <p>This is the method I am using to check the closeness condition, very simple and only checking for distance between them.<br><br></p> <pre><code>private void checkConflicts(ArrayList&lt;Flight&gt; flightsInArea) { for (int i = 0; i &lt; flightsInArea.size(); i++) { for (int j = i + 1; j &lt; flightsInArea.size(); j++) { Coordinate currentFlight1 = flightsInArea.get(i).getCurrentPosition(); Coordinate currentFlight2 = flightsInArea.get(j).getCurrentPosition(); double cathetusX = Math.pow((currentFlight1.getPositionX() - currentFlight2.getPositionX()), 2); double cathetusY = Math.pow((currentFlight1.getPositionY() - currentFlight2.getPositionY()), 2); double distance = Math.sqrt(cathetusX + cathetusY); if (distance &lt; 100) { flightsInArea.get(i).establishImage(true); flightsInArea.get(j).establishImage(true); } else { flightsInArea.get(i).establishImage(false); flightsInArea.get(j).establishImage(false); } } } } </code></pre> <p>This is the method use to establish the new image.</p> <pre><code>public void establishImage(boolean conflict) { try { if (conflict) { image = ImageIO.read(this.getClass().getResource("red_plane.png")); } else { image = ImageIO.read(this.getClass().getResource("blue_plane.png")); } } catch (IOException ex) { Logger.getLogger(Vuelo.class.getName()).log(Level.SEVERE, null, ex); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload