November 22, 201510 yr 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, 201510 yr by OSRS Sebastian
November 22, 201510 yr 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, 201510 yr by Viliuks
November 22, 201510 yr Author 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, 201510 yr by OSRS Sebastian
November 22, 201510 yr Make sure you are instanciating your GUI object before trying to set it visible ^_^
November 22, 201510 yr 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();
November 22, 201510 yr Author 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() { } }
November 22, 201510 yr 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()
November 22, 201510 yr Author 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 }
November 22, 201510 yr 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?
November 22, 201510 yr Author @Viliuks "The method Start() is undefined for the type GUI". "1 quick fix available: Create method start() in class GUI."
November 22, 201510 yr @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.
November 22, 201510 yr Author @viliuks didn't work either.. Well. Thanks for your time buddy Anyone else have the answer?
November 22, 201510 yr @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.
November 22, 201510 yr Author 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.
November 22, 201510 yr 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.
Create an account or sign in to comment