Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pass references around so that classes can communicate with each other, and not only that but with the correct active instance of the class of the other type. For instance, you could give FlightManager a FlightSimPane field:</p> <pre><code>class FightManager { private FightSimPane fightSimPane; // and fill it in the constructor: public FightManager(FightSimPane fightSimPane) { this.fightSimPane = fightSimPane; } </code></pre> <p>Then you'll be dealing with the actual visualized FightSimPane GUI object.</p> <p>Note that you'll have to take care to pass in the correct instance:</p> <pre><code>public class FightSimPane extends JPanel { FightManager FightManager = new FightManager(this); </code></pre> <p>Then you can call the public methods of FightSimPane in the FightManager class:</p> <pre><code>public void runTheFight() { System.out.println("Starting Threads"); LeftChampThread.start(); RightChampThread.start(); while ((LeftChamp.getHealth() &gt; 0) &amp;&amp; (RightChamp.getHealth() &gt; 0)) { if (RightChamp.isReadyToAttack()) { LeftChamp.setHealth(LeftChamp.getHealth() - RightChamp.getAD()); RightChamp.setNotReady(); System.out.println("Setting Left Champion test to" + Integer.toString(LeftChamp.getHealth())); // !!! **** added this ************* fightSimPane.setRightChampionLabel("Setting Left Champion test to" + Integer.toString(LeftChamp.getHealth())); } </code></pre> <p><em><strong>EDIT 1</em></strong><br> I see another potentially serious and unrelated problem here: </p> <pre><code> while ((LeftChamp.getHealth() &gt; 0) &amp;&amp; (RightChamp.getHealth() &gt; 0)) { //......... } </code></pre> <p>This code appears to be called on the main Swing thread, the EDT and it's nature (while (true)) suggests that it has a very good chance of locking up the EDT bringing your Swing GUI's graphics processing and updating and all user interactions to a screeching halt. You may need to use a Swing Timer for this or a background thread so as to leave the EDT free to do its necessary work.</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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