"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
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.
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: class FightManager { private FightSimPane fightSimPane; // and fill it in the constructor: public FightManager(FightSimPane fightSimPane) { this. FightSimPane = fightSimPane; } Then you'll be dealing with the actual visualized FightSimPane GUI object.
Note that you'll have to take care to pass in the correct instance: public class FightSimPane extends JPanel { FightManager FightManager = new FightManager(this); Then you can call the public methods of FightSimPane in the FightManager class: public void runTheFight() { System.out. Println("Starting Threads"); LeftChampThread.start(); RightChampThread.start(); while ((LeftChamp.getHealth() > 0) && (RightChamp.getHealth() > 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())); } EDIT 1 I see another potentially serious and unrelated problem here: while ((LeftChamp.getHealth() > 0) && (RightChamp.getHealth() > 0)) { //......... } 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.
Ok that helps, now my issue is with the setRightChampionLabel(String s) and setLeftChampionLabel(String s) methods. Is there any reason I cant put lblChampionleft. SetText(s); in there?
– Thad Blankenship Oct 6 at 2:59 @ThadBlankenship: Yeah, don't declare the JLabels inside of a method or constructor! That way their visibility is limited to the same method or constructor. Instead declare these guys as a non-static class field and allow it to be visible throughout the class.
This has nothing to do with Swing but instead is basic Java variable scope 101. – Hovercraft Full Of Eels Oct 6 at 3:02 Ah, I was using windowbuilder and it declared them in the constructor. Whats up with that?
– Thad Blankenship Oct 6 at 3:06 @ThadBlankenship: another argument for not using code generators until you are very very familiar with the library. – Hovercraft Full Of Eels Oct 6 at 3:08 I see your point there but at the same time I feel I learn best by looking at code and then climbing the walls myself when I hit them. I got it all working now, and moved the while loop to a separate thread.
Works flawlessly. Thank you very much sir. – Thad Blankenship Oct 6 at 3:10.
Declare the reference variable of FightSimPane class in FightManager class and pass the reference of FightSimPane object via the constructor of FightManager. In FightManager class, public class FightManager { Champion LeftChamp = new Champion(); Champion RightChamp = new Champion(); private FightSimPane pane; public FightManager(FightSimPane pane) { this. Pane=pane;} public FightManager() { } .... Using "pane" reference variable you can access accessible elements of FightSimPane class.
Modify the FightSimPane code, public class FightSimPane extends JPanel { FightManager fightManager; public FightSimPane() { fightManager= new FightManager(this); ... }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.