Mexiah Posted August 14, 2015 Share Posted August 14, 2015 Hi guys, I was trying to make a menu where users select what scenarios to include from my script and was told to use JFrame. I've watched some tutorials on it but I can't figure out how to include it in my script. Any help to get out there? :-) This is what I have so far, btw, and it clearly doesn't work xD public class SlayerBot extends (Script && JFrame) { private Frame() { //Code } } Quote Link to comment Share on other sites More sharing options...
Joseph Posted August 14, 2015 Share Posted August 14, 2015 Nope only a class can extend only one class. You'll have a script class and a sepreate jframe class Quote Link to comment Share on other sites More sharing options...
Deceiver Posted August 14, 2015 Share Posted August 14, 2015 https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html https://docs.oracle.com/javase/tutorial/uiswing/painting/step1.html Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted August 14, 2015 Share Posted August 14, 2015 Can only extend one class. If you want multiple inheritance you need to extend a class that extends a class that extends... you get it. Make another class Class Gui extends JFrame Quote Link to comment Share on other sites More sharing options...
Mexiah Posted August 14, 2015 Author Share Posted August 14, 2015 Then how do I call it in my script? Quote Link to comment Share on other sites More sharing options...
Botre Posted August 14, 2015 Share Posted August 14, 2015 Then how do I call it in my script? http://www.programmingsimplified.com/java/source-code/java-program-multiple-classes Quote Link to comment Share on other sites More sharing options...
Apaec Posted August 14, 2015 Share Posted August 14, 2015 (edited) Gui class: public class Gui extends JFrame { public Gui() { //constructor setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); //stick your Gui code in here for the jframe. You can use windowbuilder plugin for eclipse to design it a bit simpler. } } Main class: private Gui GUI; @Override public void onStart() { GUI = new Gui(); GUI.setVisible(true); } merry christmas apa Edited August 14, 2015 by Apaec Quote Link to comment Share on other sites More sharing options...
Twin Posted August 14, 2015 Share Posted August 14, 2015 Gui class: public class Gui extends JFrame { public Gui() { //constructor setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); //stick your Gui code in here for the jframe. You can use windowbuilder plugin for eclipse to design it a bit simpler. } } Main class: private Gui GUI; @Override public void onStart() { GUI = new Gui(); GUI.setVisible(true); } merry christmas apa It's Christmas in August! 1 Quote Link to comment Share on other sites More sharing options...
RickyD Posted August 14, 2015 Share Posted August 14, 2015 (edited) Hi guys, I was trying to make a menu where users select what scenarios to include from my script and was told to use JFrame. I've watched some tutorials on it but I can't figure out how to include it in my script. Any help to get out there? :-) This is what I have so far, btw, and it clearly doesn't work xD public class SlayerBot extends (Script && JFrame) { private Frame() { //Code } } code your gui in a seperate class (so that the gui class itself extends JFrame) then you declare a new instance in your slayerbot class the way Apaec had it written Edited August 14, 2015 by RickyD Quote Link to comment Share on other sites More sharing options...
Mexiah Posted August 15, 2015 Author Share Posted August 15, 2015 Alright, so I've figured out that making this using Window Builder is actually pretty simple. I just still can't figure out how to get the two classes to work together. I get the onStart-code calling the GUI but how do I make the GUI change variables in my main script? Or should I declare the variables in the GUI and then pass them to my SlayerBot-class? There are no "classes" in C so this concept is not familiar to me :-P :-P Quote Link to comment Share on other sites More sharing options...
Botre Posted August 15, 2015 Share Posted August 15, 2015 (edited) Alright, so I've figured out that making this using Window Builder is actually pretty simple. I just still can't figure out how to get the two classes to work together. I get the onStart-code calling the GUI but how do I make the GUI change variables in my main script? Or should I declare the variables in the GUI and then pass them to my SlayerBot-class? There are no "classes" in C so this concept is not familiar to me :-P :-P struct GUI { int valueA; int valueB; }; int main() // Your script { struct GUI MyGUI; // > Load GUI and set values here < int valueA = MyGUI.valueA; int valueB = MyGUI.valueB; return 0; } Think of a class as a struct with more functionality (crude definition but might help you). Edited August 15, 2015 by Botre Quote Link to comment Share on other sites More sharing options...