Jump to content

Another question from me! [GUI]


Sebastian

Recommended Posts

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 by OSRS Sebastian
Link to comment
Share on other sites

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 by Viliuks
  • Like 1
Link to comment
Share on other sites

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 by OSRS Sebastian
Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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() {
			
		}
}

Link to comment
Share on other sites

 

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()

Link to comment
Share on other sites

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
			
		}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...