javafx

JavaFX New Scene on Button Click

|▌冷眼眸甩不掉的悲伤 提交于 2020-03-09 19:56:04
问题 The title may be a bit vague, so allow me to define it a little better. I have a working piece of code (down below): a simple main menu for a game I am working on. Everything works well, except for the Start button. What I want to be able to do is click the Start button, and have a new scene appear on the same stage (window). I do not want to see a new window open. I have talked with someone more experienced in Java, and they told me to create separate classes for the MenuFX and the GameFX.

JavaFX New Scene on Button Click

試著忘記壹切 提交于 2020-03-09 19:54:17
问题 The title may be a bit vague, so allow me to define it a little better. I have a working piece of code (down below): a simple main menu for a game I am working on. Everything works well, except for the Start button. What I want to be able to do is click the Start button, and have a new scene appear on the same stage (window). I do not want to see a new window open. I have talked with someone more experienced in Java, and they told me to create separate classes for the MenuFX and the GameFX.

Cannot Construct An Image Object With Relative File Path WIthout Using file: Prefix

心已入冬 提交于 2020-03-06 04:20:31
问题 I have been trying to create an image object like this: Image img = new Image("images/jack.png"); or Image img = new Image("jack.png"); or /jack.png or /images/jack.png etc. I have looked up the working directory using System.getProperty("user.dir") and it is indeed where I put my image file. When I use file: prefix, it does work, like so: Image img = new Image("file:images/jack.png"); However, it is also supposed to work without using it. In the textbook it is done without file: . I've seen

JavaFX: Creating a board grid with Permanin twist

谁说我不能喝 提交于 2020-03-05 06:08:29
问题 I am creating a board game (first ported to JavaFX) in which the player must kill the opponent's piece going through a loop. The above is provided on the Wikipedia page for Surakurta (another name for Permanin). But, I have been only able to build a grid of this sort: How can I create those roundabouts in the corners? Implementation details for already built grid: GridPane filled with 36 BoardInput extends javafx.scene.control.Button objects. These objects are special because they

How do I target my random colour variable in my IF statement?

我的梦境 提交于 2020-03-05 00:10:47
问题 I have a question that is leading from the chosen best answer from my previous post: How can I use randomisation to specify different object parameters to a single iteration in a loop? I'm new to stack and wasn't sure of the best way to reference that post. I have the code written as advised from the post above, however, now I'm attempting to have a method run different lines of code based off the colour of the 'brick' that is interacted with via my 'ball' object: public Color brickColour;

How to achieve JavaFX and non-JavaFX interaction?

泪湿孤枕 提交于 2020-03-03 05:18:05
问题 I have started using JavaFX to create a window for user interaction, to be used in another, non-JavaFX, program. My main program is called the Abc class, having a main method. This is a non-JavaFX program, but plain vanilla Java. This program runs some activities, then asks the user to select a String from a list of possible Strings . This user interaction is done with a JavaFX program called MenuSelector . The user selects one String , which will then be returned to Abc for further

How to convert an observable list to an array list? Java

此生再无相见时 提交于 2020-03-02 09:27:38
问题 I'm trying to get all the items in a table view and place them in an array list for further processing. This is what I'm trying to achieve but obviously it won't work. ArrayList<Consultation> showing = consultationTable.getItems(); 回答1: Nice and recommended solution: List<Consultation> showing = provider.getItems(); Solution to use only if necessary: List<Consultation> consultations = provider.getItems(); ArrayList<Consultation> showing; if (consultations instanceof ArrayList<?>) { showing =

How to convert an observable list to an array list? Java

和自甴很熟 提交于 2020-03-02 09:27:28
问题 I'm trying to get all the items in a table view and place them in an array list for further processing. This is what I'm trying to achieve but obviously it won't work. ArrayList<Consultation> showing = consultationTable.getItems(); 回答1: Nice and recommended solution: List<Consultation> showing = provider.getItems(); Solution to use only if necessary: List<Consultation> consultations = provider.getItems(); ArrayList<Consultation> showing; if (consultations instanceof ArrayList<?>) { showing =

javafx实现拖人文件到node,将node里面的内容为文件保存

假装没事ソ 提交于 2020-03-02 03:08:13
最近研究了下javafx客户端人性化方面的,拖来拖去什么的最爱了,接下来给大家讲解下javafx怎么获取拖入的文件和将node里面的内容拖出为文件 1.获取拖入的文件 //build drag txtAreaChangePane.setOnDragOver(new EventHandler<DragEvent>() { //node添加拖入文件事件 public void handle(DragEvent event) { Dragboard dragboard = event.getDragboard(); if (dragboard.hasFiles()) { File file = dragboard.getFiles().get(0); if (file.getAbsolutePath().endsWith(".java")) { //用来过滤拖入类型 event.acceptTransferModes(TransferMode.COPY);//接受拖入文件 } } } }); txtAreaChangePane.setOnDragDropped(new EventHandler<DragEvent>() { //拖入后松开鼠标触发的事件 public void handle(DragEvent event) { // get drag enter file

How to access UI components from SceneBuilder in JavaFX

我与影子孤独终老i 提交于 2020-03-01 01:49:47
问题 (DUPLICATE & SOLVED - see answer below) I'm doing my first steps in JavaFX and it seems quite hard to use the "SceneBuilder". I'm used to Android and the QtCreator. It looks to me that there is accessing the UI components much easier. Something like findViewById(R.id.btnPushMe); <- Android Code Actually I got an solution but it is quite uncomfortable to use. This looks as this: FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("../fmxl/main.fxml")); AnchorPane pane = loader.load();