Sebastian Posted November 22, 2015 Share Posted November 22, 2015 (edited) Hey everyone, how are you all doing? This week i have been focussing on Java GUI. I have watched the JavaFX tutorial from Thenewboston. But now. I want to create a GUI for my script, but i have no idea how to make the GUI visible when the script has been selected. I have asked this once, and i got answers. But i tried to look up the topic, and i think it has been deleted. Hope you all can help me. Sebastian. Edited November 22, 2015 by OSRS Sebastian Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 (edited) If you got another class you call the method from another class from onStart in the main class I.e onStart{ GUI.Initialise(); } Gui represents the class. initialise represents the method you have that contains the gui components. EDIT: and make sure your method in the gui class has: jFrame.setVisible(true); Edited November 22, 2015 by Viliuks 1 Quote Link to comment Share on other sites More sharing options...
Sebastian Posted November 22, 2015 Author Share Posted November 22, 2015 (edited) If you got another class you call the method from another class from onStart in the main class I.e onStart{ GUI.Initialise(); } Gui represents the class. initialise represents the method you have that contains the gui components. I tried this. Got an error that i needed to create a method. I did, but the gui didn't pop up. Edit: Didn't read your edit before posting this. But, when i do. jFrame gives an error. Maybe because i use JavaFX? Edited November 22, 2015 by OSRS Sebastian Quote Link to comment Share on other sites More sharing options...
Extreme Scripts Posted November 22, 2015 Share Posted November 22, 2015 Make sure you are instanciating your GUI object before trying to set it visible ^_^ Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 I tried this. Got an error that i needed to create a method. I did, but the gui didn't pop up. Edit: Didn't read your edit before posting this. But, when i do. jFrame gives an error. Maybe because i use JavaFX? no jFrame. is how you named your JFrame its the name you gave JFrame jFrame = new JFrame(); Quote Link to comment Share on other sites More sharing options...
Sebastian Posted November 22, 2015 Author Share Posted November 22, 2015 You lost me there. I wanted to import this GUI.java to my main.java wich is the bot script. What you see, is one GUI tutorial from Thenewboston. Maybe you can help me better now: import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class GUI extends Application{ Stage window; Scene scene; Button button; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { window = primaryStage; window.setTitle("Choose something"); button = new Button("Click me"); ChoiceBox<String> choiceBox = new ChoiceBox<>(); choiceBox.getItems().add("Apples"); choiceBox.getItems().add("Bananas"); choiceBox.getItems().addAll("Bacon", "Ham", "Meatballs"); choiceBox.setValue("Apples"); button.setOnAction(e -> getChoice(choiceBox)); VBox layout = new VBox(10); layout.setPadding(new Insets(20, 20, 20, 20)); layout.getChildren().addAll(choiceBox, button); scene = new Scene(layout, 300, 250); window.setScene(scene); window.show(); } //To get the value of the selected item private void getChoice(ChoiceBox<String> choiceBox){ String food = choiceBox.getValue(); System.out.println(food); } public static void Initialise() { } } Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 You lost me there. I wanted to import this GUI.java to my main.java wich is the bot script. What you see, is one GUI tutorial from Thenewboston. Maybe you can help me better now: import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class GUI extends Application{ Stage window; Scene scene; Button button; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { window = primaryStage; window.setTitle("Choose something"); button = new Button("Click me"); ChoiceBox<String> choiceBox = new ChoiceBox<>(); choiceBox.getItems().add("Apples"); choiceBox.getItems().add("Bananas"); choiceBox.getItems().addAll("Bacon", "Ham", "Meatballs"); choiceBox.setValue("Apples"); button.setOnAction(e -> getChoice(choiceBox)); VBox layout = new VBox(10); layout.setPadding(new Insets(20, 20, 20, 20)); layout.getChildren().addAll(choiceBox, button); scene = new Scene(layout, 300, 250); window.setScene(scene); window.show(); } //To get the value of the selected item private void getChoice(ChoiceBox<String> choiceBox){ String food = choiceBox.getValue(); System.out.println(food); } public static void Initialise() { } } in on start put: GUI.Start(); and you don't need the jFrame.setVisible(true), you already have window.show() Quote Link to comment Share on other sites More sharing options...
Sebastian Posted November 22, 2015 Author Share Posted November 22, 2015 in on start put: GUI.Start(); and you don't need the jFrame.setVisible(true), you already have window.show() Didn't do anything. It gave an error that i needed to create a method in GUI.java. So i did, but left it like this: public static void Start() { // TODO Auto-generated method stub } Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 Didn't do anything. It gave an error that i needed to create a method in GUI.java. So i did, but left it like this: public static void Start() { // TODO Auto-generated method stub } What error? Quote Link to comment Share on other sites More sharing options...
Sebastian Posted November 22, 2015 Author Share Posted November 22, 2015 @Viliuks "The method Start() is undefined for the type GUI". "1 quick fix available: Create method start() in class GUI." Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 @Viliuks "The method Start() is undefined for the type GUI". "1 quick fix available: Create method start() in class GUI." it could possibly be: GUI.main(); if it doesn't I'm clueless then. Quote Link to comment Share on other sites More sharing options...
Sebastian Posted November 22, 2015 Author Share Posted November 22, 2015 @viliuks didn't work either.. Well. Thanks for your time buddy Anyone else have the answer? Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 @viliuks didn't work either.. Well. Thanks for your time buddy Anyone else have the answer? If you want I could give you an already made java gui which you could use. 1 Quote Link to comment Share on other sites More sharing options...
Sebastian Posted November 22, 2015 Author Share Posted November 22, 2015 If you want I could give you an already made java gui which you could use. Would be very sweet. I can learn from that. Quote Link to comment Share on other sites More sharing options...
Vilius Posted November 22, 2015 Share Posted November 22, 2015 Would be very sweet. I can learn from that. http://pastebin.com/FYnKDJTE just add: GUI.Window(this); in the onStart method and try to look what each thing does although I commented stuff in. 1 Quote Link to comment Share on other sites More sharing options...