- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题已得到解答,我的问题已得到解决。我已经用我的最终解决方案更新了此帖子
我正在做这个学校作业(测验程序),我们最初只要求将其作为纯文本的控制台游戏来完成,但我想挑战自己并尝试在 JavaFX 中创建它,而我们才刚刚开始学习有关.
这是一款回合制问答游戏,玩家将面临一个问题,需要通过两个按钮(对或错按钮)回答对/错
游戏流程:
我正在运行一个 for 循环,只要 ArrayList 中还存在问题,该循环就会继续。
理想的流程是这样的:
0) 输入姓名并按:开始游戏按钮1) 向玩家 1 提出问题。2) 通过 True 按钮或 False 按钮接收输入。3) 将输入与从数组中提取的正确答案进行比较。4) 如果正确,用户获得 1 分 - 如果错误,则继续玩家 2。5) 换成玩家二并重新开始,直到 ArrayList 中不再有问题为止。
什么有效我的循环“正常运行”,因为它会更改播放器并继续,直到 ArrayList 中不再有任何问题为止。
问题我希望 for 循环等待用户通过 true/false 按钮输入。然而,for 循环运行整个程序而不等待输入。
问题是否可以“暂停”for 循环并让它等待两个按钮之一的输入?您是否建议我使用其他方法来处理这个问题?
如果您愿意直接解决这个问题,我会非常高兴。无论是通过这个论坛还是给我发送进一步阅读的链接都可以。我似乎无法通过谷歌搜索或搜索这个论坛找到解决方案。
代码中充满了 System.out.println() 供我查看程序运行了多远。请把目光移开。
另外...任何有关如何改进代码的建议将不胜感激。刚接触 Java 编程 8 周,很想学习如何更聪明地做事。
主要代码
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Expert Quiz Game");
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller 代码
package sample;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import java.util.Random;
public class Controller {
@FXML
TextField player1;
@FXML
TextField player2;
@FXML
Text score1;
@FXML
Text score2;
@FXML
Text questionText;
@FXML
Text questionsLeft;
@FXML
Text gameStatus;
@FXML
Button startGame;
@FXML
Button buttonTrue;
@FXML
Button buttonFalse;
//@FXML
//Button nextRound;
@FXML
private void handleStartGame(ActionEvent event) {
// ******* DECLARE VARIABLES ********
String playerOneName = player1.getText(); //Saves the name for later use
String playerTwoName = player2.getText(); //Saves the name for later use
int playerOneScore = 0;
int playerTwoScore = 0;
Random randomQuestionNumber1 = new Random();
//Random randomQuestionNumber2 = new Random();
System.out.println(playerOneName + " TEST"); //To TEST if the name is saved
System.out.println(playerTwoName + " TEST"); //To TEST if the name is saved
// ******* DECLARE QUESTION ARRAY ********
ArrayList<String> questionsArray = new ArrayList<String>();
questionsArray.add("Question 1");
questionsArray.add("Question 2");
questionsArray.add("Question 3");
questionsArray.add("Question 4");
questionsArray.add("Question 5");
questionsArray.add("Question 6");
// ******* DECLARE ANSWER ARRAY ********
ArrayList<String> answerArray = new ArrayList<String>();
answerArray.add("True");
answerArray.add("True");
answerArray.add("False");
answerArray.add("True");
answerArray.add("False");
answerArray.add("True");
//int randomQuestionA = randomQuestionNumber1.nextInt(questionsArray.size()); //+0
//int randomQuestionB = randomQuestionNumber2.nextInt(questionsArray.size()); //+0
//Button clickedButton = (Button) event.getTarget();
//String buttonLabel = clickedButton.getText();
int player = 1;
for (int i = 0; i < questionsArray.size(); i++) {
if (player == 1) {
int randomQuestionA = randomQuestionNumber1.nextInt(questionsArray.size());
// ****** RETRIEVE AND PRESENT FIRST QUESTION ******
System.out.println("1. Player: " + playerOneName); // WRITE TO CONSOLE THE CURRENT PLAYER * CAN BE REMOVED
questionText.setText("Question: " + questionsArray.get(randomQuestionA)); // PRINTS QUESTION TO THE UI
System.out.println("2. "+questionsArray.get(randomQuestionA)); // WRITES TO CONSOLE THE QUESTION * CAN BE REMOVED
// ****** GET ANSWER FOR THE QUESTION ******
String answerFromArray = answerArray.get(randomQuestionA); // TAKES THE ANSWER FROM THE ARRAY AND SAVES AS A NEW STRING
System.out.println("3." + answerArray.get(randomQuestionA)); // WRITES THE ANSWER FROM THE ARRAY TO CONSOLE * CAN BE REMOVED
// ****** TEST IF ANSWER IS TRUE ******
String buttonTrueText = buttonTrue.getText(); // SAVES THE BUTTON TEXT AS A STRING FOR LATER COMPARISON
String buttonFalseText = buttonFalse.getText(); // SAVES THE BUTTON TEXT AS A STRING FOR LATER COMPARISON
// ****** IF TRUE, THEN COUNT ONE UP IN SCORE ******
buttonTrue.setOnAction(e -> {
System.out.println("4. Now running"); // WRITES TO CONSOLE * CAN BE REMOVED
String buttonAnswer = " "; // INITIALIZES THE VARIABLE WITH AN EMPTY STRING
handleButtonAnswer(event);
/**if (buttonText.equals("True")) { // REGISTERS THE BUTTON PRESSED AND SAVES IT IN A VARIABLE
buttonAnswer = "True";
} else if (buttonText.equals("False")) { // REGISTERS THE BUTTON PRESSED AND SAVES IT IN A VARIABLE
buttonAnswer = "False";
}**/
if (buttonAnswer == "True" || buttonAnswer == "False") {
System.out.println("5. Test");
}
System.out.println("6. "+buttonAnswer);
if (answerFromArray.equals(buttonAnswer)) {
System.out.println("7. Answer was correct - Need to count one up in score");//
}
score1.setText("Points: " + playerOneScore+1);
System.out.println("8. "+playerOneScore+1);
questionsArray.remove(randomQuestionA); // REMOVES QUESTION FROM ARRAYLIST
answerArray.remove(randomQuestionA); // REMOVES ANSWER FROM ARRAYLIST
int remainingQuestions = questionsArray.size();
questionsLeft.setText(remainingQuestions + " questions left");
});
// ****** REMOVE THAT QUESTION + ANSWER FROM THE ARRAY ******
// ****** CHANGE PLAYER AND START AGAIN ******
player = 2;
System.out.println("Changing to player " +player);
} else if (player == 2) {
//clickedButton.setText("O");
int randomQuestionA = randomQuestionNumber1.nextInt(questionsArray.size());
// ****** RETRIEVE AND PRESENT FIRST QUESTION ******
System.out.println("1. Player: " + playerOneName); // WRITE TO CONSOLE THE CURRENT PLAYER * CAN BE REMOVED
questionText.setText("Question: " + questionsArray.get(randomQuestionA)); // PRINTS QUESTION TO THE UI
System.out.println("2. "+questionsArray.get(randomQuestionA)); // WRITES TO CONSOLE THE QUESTION * CAN BE REMOVED
// ****** GET ANSWER FOR THE QUESTION ******
String answerFromArray = answerArray.get(randomQuestionA); // TAKES THE ANSWER FROM THE ARRAY AND SAVES AS A NEW STRING
System.out.println("3." + answerArray.get(randomQuestionA)); // WRITES THE ANSWER FROM THE ARRAY TO CONSOLE * CAN BE REMOVED
// ****** TEST IF ANSWER IS TRUE ******
String buttonTrueText = buttonTrue.getText(); // SAVES THE BUTTON TEXT AS A STRING FOR LATER COMPARISON
String buttonFalseText = buttonFalse.getText(); // SAVES THE BUTTON TEXT AS A STRING FOR LATER COMPARISON
// ****** IF TRUE, THEN COUNT ONE UP IN SCORE ******
buttonTrue.setOnAction(e -> {
System.out.println("4. Now running"); // WRITES TO CONSOLE * CAN BE REMOVED
String buttonAnswer = " "; // INITIALIZES THE VARIABLE WITH AN EMPTY STRING
handleButtonAnswer(event);
/**if (buttonText.equals("True")) { // REGISTERS THE BUTTON PRESSED AND SAVES IT IN A VARIABLE
buttonAnswer = "True";
} else if (buttonText.equals("False")) { // REGISTERS THE BUTTON PRESSED AND SAVES IT IN A VARIABLE
buttonAnswer = "False";
}**/
if (buttonAnswer == "True" || buttonAnswer == "False") {
System.out.println("5. Test");
}
System.out.println("6. "+buttonAnswer);
if (answerFromArray.equals(buttonAnswer)) {
System.out.println("7. Answer was correct - Need to count one up in score");//
}
score1.setText("Points: " + playerOneScore+1);
System.out.println("8. "+playerOneScore+1);
questionsArray.remove(randomQuestionA); // REMOVES QUESTION FROM ARRAYLIST
answerArray.remove(randomQuestionA); // REMOVES ANSWER FROM ARRAYLIST
int remainingQuestions = questionsArray.size();
questionsLeft.setText(remainingQuestions + " questions left");
});
// ****** REMOVE THAT QUESTION + ANSWER FROM THE ARRAY ******
// ****** CHANGE PLAYER AND START AGAIN ******
player = 1;
System.out.println("Changing to player " +player);
}
}
}
@FXML
private String handleButtonAnswer(ActionEvent event) {
String buttonAnswer = "";
// (1)
Button b = (Button) event.getSource();
// (2)
String t = b.getText();
System.out.println("4. the text on the button was: "+t);
if (t.equals("True")){
buttonAnswer = "True"; // demo
}else if (t.equals("False")){
buttonAnswer = "False";
}
return buttonAnswer;
}
}
fxml 代码
设计尚未完成 - 在正确设计样式之前需要它发挥作用
<?xml version="1.0" encoding="UTF-8"?><?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="794.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<Label layoutX="225.0" layoutY="47.0" prefHeight="66.0" prefWidth="334.0" text="Java ExpertQuiz" textAlignment="CENTER">
<font>
<Font name="Cambria Bold" size="45.0" />
</font>
</Label>
<TextField fx:id="player1" layoutX="79.0" layoutY="154.0" prefHeight="39.0" prefWidth="201.0" promptText="Enter name for player1" />
<TextField fx:id="player2" layoutX="503.0" layoutY="154.0" prefHeight="39.0" prefWidth="222.0" promptText="Enter name for player2" />
<Text fx:id="score1" layoutX="79.0" layoutY="232.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Ponits" />
<Text fx:id="score2" layoutX="503.0" layoutY="232.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Points" />
<Text fx:id="questionText" layoutX="38.0" layoutY="315.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Question" textAlignment="CENTER" wrappingWidth="717.1240234375">
<font>
<Font size="38.0" />
</font>
</Text>
<Button fx:id="startGame" layoutX="318.0" layoutY="154.0" mnemonicParsing="false" onAction="#handleStartGame" text="Start game" />
<Text fx:id="questionsLeft" layoutX="301.0" layoutY="505.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Questions left: " textAlignment="CENTER" wrappingWidth="191.9072265625" />
<Text fx:id="gameStatus" layoutX="320.0" layoutY="547.0" strokeType="OUTSIDE" strokeWidth="0.0" text="The winner is:" />
<Button fx:id="buttonTrue" layoutX="150.0" layoutY="390.0" mnemonicParsing="false" onAction="#handleButtonAnswer" text="True" />
<Button fx:id="buttonFalse" layoutX="582.0" layoutY="390.0" mnemonicParsing="false" onAction="#handleButtonAnswer" text="False" />
</children>
</AnchorPane>
一切正常 - 这是我的最终解决方案
package sample;
import java.net.URL;
import java.util.*;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class Controller {
@FXML
TextField player1;
@FXML
TextField player2;
@FXML
Text score1;
@FXML
Text score2;
@FXML
Text statusText;
@FXML
Text questionsLeft;
@FXML
Text currentPlayer;
@FXML
Button startGame;
@FXML
Button buttonTrue;
@FXML
Button buttonFalse;
@FXML
Button nextRound;
private ArrayList<String> questionsArray = new ArrayList<String>();
private ArrayList<String> answerArray = new ArrayList<String>();
private int player = 0;
private int remainingQuestions = 0;
private int playerOneScore;
private int playerTwoScore;
private String playerOneName = "";
private String playerTwoName = "";
private String answerFromArray = "";
private String answerButtonText = "";
private Random randomQuestionNumber = new Random();
private int randomQuestion = 0;
@FXML
private void handleStartGame(ActionEvent event) {
// ******* DECLARE VARIABLES ********
playerOneName = player1.getText(); //Saves the name for later use
playerTwoName = player2.getText(); //Saves the name for later use
score1.setText(playerOneName+ " has: 0 points;");
score2.setText(playerTwoName+ " has: 0 points;");
playerOneScore = 0;
playerTwoScore = 0;
System.out.println(playerOneName + " TEST"); //To TEST if the name is saved
System.out.println(playerTwoName + " TEST"); //To TEST if the name is saved
// ******* DECLARE QUESTION ARRAY ********
questionsArray.add("Question 1");
questionsArray.add("Question 2");
questionsArray.add("Question 3");
questionsArray.add("Question 4");
questionsArray.add("Question 5");
questionsArray.add("Question 6");
// ******* DECLARE ANSWER ARRAY ********
answerArray.add("True");
answerArray.add("True");
answerArray.add("False");
answerArray.add("True");
answerArray.add("False");
answerArray.add("True");
// ******* THIS IS THE PLAYER STARTING THE ROUND ******
player = 1;
// ****** RETRIEVE AND PRESENT FIRST QUESTION - THIS WILL ONLY BE USED TO START THE PROGRAM ******
randomQuestion = randomQuestionNumber.nextInt(questionsArray.size()); // GENERATES A RANDOM NUMBER TO PICK A RANDOM QUESTION FROM ARRAYLIST
statusText.setText("Question: " + questionsArray.get(randomQuestion)); // PRINTS THE RANDOM QUESTION TO THE UI
currentPlayer.setText("Current Player: "+playerOneName);
buttonFalse.setDisable(false);
buttonTrue.setDisable(false);
startGame.setDisable(true);
}
@FXML
private void handleButtonAnswer(ActionEvent event) {
Button answerButtonClicked = (Button) event.getSource();
answerButtonText = answerButtonClicked.getText();
answerFromArray = answerArray.get(randomQuestion); // PICKS THE ANSWER MATCHING THE QUESTION GENERATED BY THE RANDOM NUMBER
if (answerFromArray.equals(answerButtonText)) {
statusText.setText("Answer was correct! You've been awarded 1 point");
if(player == 1){
playerOneScore = playerOneScore+1;
score1.setText(playerOneName+ " has: "+playerOneScore+" points;");
}else if(player == 2){
playerTwoScore = playerTwoScore+1;
score2.setText(playerTwoName+ " has: "+playerTwoScore+" points;");
}
}else{
statusText.setText("Answer was incorrect! No point was given.");
}
nextRound.setDisable(false);
buttonFalse.setDisable(true);
buttonTrue.setDisable(true);
}
@FXML
private void handleButtonNext(ActionEvent event) {
if(player == 1){
player = 2;
currentPlayer.setText("Current Player: "+playerTwoName);
}else if(player == 2){
player = 1;
currentPlayer.setText("Current Player: "+playerOneName);
}
questionsArray.remove(randomQuestion); // REMOVES QUESTION FROM ARRAYLIST
answerArray.remove(randomQuestion); // REMOVES ANSWER FROM ARRAYLIST
remainingQuestions = questionsArray.size();
questionsLeft.setText(remainingQuestions + " questions left");
if(questionsArray.size()!=0){
randomQuestion = randomQuestionNumber.nextInt(questionsArray.size());
statusText.setText("Question: " + questionsArray.get(randomQuestion)); // PRINTS QUESTION TO THE UI
}else{
if(playerOneScore>playerTwoScore){
questionsLeft.setText("Game is over. The winner is: "+playerOneName);
}else if(playerTwoScore>playerOneScore){
questionsLeft.setText("Game is over. The winner is: "+playerTwoName);
}else{
questionsLeft.setText("The game ended in a DRAW. ");
}
startGame.setDisable(false);
buttonFalse.setDisable(true);
buttonTrue.setDisable(true);
}
nextRound.setDisable(true);
buttonFalse.setDisable(false);
buttonTrue.setDisable(false);
}
}
fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<Label layoutX="233.0" layoutY="46.0" prefHeight="66.0" prefWidth="334.0" text="Java ExpertQuiz" textAlignment="CENTER">
<font>
<Font name="Cambria Bold" size="45.0" />
</font>
</Label>
<TextField fx:id="player1" layoutX="79.0" layoutY="154.0" opacity="0.5" prefHeight="39.0" prefWidth="201.0" promptText="Enter name for player 1" />
<TextField fx:id="player2" layoutX="503.0" layoutY="154.0" opacity="0.5" prefHeight="39.0" prefWidth="222.0" promptText="Enter name for player 2" />
<Text fx:id="score1" layoutX="114.0" layoutY="224.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Player 1 has: 0 points" />
<Text fx:id="score2" layoutX="558.0" layoutY="224.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Player 2 has: 0 points" />
<Text fx:id="statusText" layoutX="41.0" layoutY="315.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Question" textAlignment="CENTER" wrappingWidth="717.1240234375">
<font>
<Font size="38.0" />
</font>
</Text>
<Button fx:id="startGame" layoutX="363.0" layoutY="161.0" mnemonicParsing="false" onAction="#handleStartGame" text="Start game" />
<Text fx:id="questionsLeft" layoutX="304.0" layoutY="473.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Questions left: " textAlignment="CENTER" wrappingWidth="191.9072265625">
<font>
<Font size="18.0" />
</font></Text>
<Button fx:id="buttonTrue" disable="true" layoutX="150.0" layoutY="378.0" mnemonicParsing="false" onAction="#handleButtonAnswer" text="True" />
<Button fx:id="buttonFalse" disable="true" layoutX="592.0" layoutY="378.0" mnemonicParsing="false" onAction="#handleButtonAnswer" text="False" />
<Button fx:id="nextRound" disable="true" layoutX="354.0" layoutY="378.0" mnemonicParsing="false" onAction="#handleButtonNext" text="Next Question" />
<Text fx:id="currentPlayer" layoutX="355.0" layoutY="260.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Current player:">
<font>
<Font size="14.0" />
</font>
</Text>
</children>
最佳答案
您可以将循环设为一个单独的函数,然后在放置按钮时调用它,而不是将其视为暂停循环。在这种情况下,它不再是循环,它只需将循环的索引存储为函数外部的变量,或者您可以使用索引作为参数来调用函数。我认为你的整个 handleStartGame
可以进一步拆分。一个好的经验法则是,一个函数应该执行一项特定任务,这将使程序更容易继续运行。如果您遇到任何问题,请随时发表评论!
关于JavaFX - 需要一个 for 循环来暂停并等待按钮输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53379491/
我不知道这是不是问这种问题的最佳地点, 我看到一些 JavaFX伙计们,重新标记 一些问题通过替换 javafx来自 javafx-2并采用新的 javafx-8 .它被弃用了还是什么? 编辑 : 不
错误本身: Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.bas
这个想法是让一个应用程序在每个显示器上显示两个不同的窗口(阶段),该应用程序应该知道计算机有多少个显示器及其分辨率。 javafx有可能吗? 最佳答案 对于当前版本的 JavaFX (2.2),您可以
我正在将我的项目从 javafx 1.3 转换为 javafx 2.1。但我对 javafx.lang 有疑问包裹。 最佳答案 JavaFX 1.3 lang 包内容被拆分并移至下一个位置: 时长变为
当我尝试将标签添加到 gridpane 中时,如第二张图片所示,它不起作用。我已经尝试了很多东西,比如添加 CSS,但它仍然无法正常工作。为什么第 113 和 114 行不起作用? (opcje.se
我有一个JavaFX ContextMenu分配给滚动面板的鼠标右键单击。它会打开,但在滚动 Pane 外部单击时不会关闭。我可以在滚动 Pane 中添加另一个鼠标事件以将其隐藏,但这只能解决1个问题
我有一个tableview,其中附有一个可观察到的自定义类对象的列表(类类型:SalesInvoiceNetSale)。该表中的所有数据都可以正常显示。可观察列表中的最后一项是总计行(类类型:Sale
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我想知道如何在JavaFX中绘制半圆。我尝试使用Shape和QuadCurve,但无法制作出完美的半圆。 这是我要绘制的图片: 最佳答案 您链接的图片实际上是一个半圆环。您可以通过绘制嵌套的2条圆弧和
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在寻找 JavaFX 支持的图像类型(最新)列表,例如PNG、JPEG、TIFF。不同的搜索引擎没有帮助......知道从哪里开始吗? 更特别的是,我对 16 位灰度图像(不同格式)和罕见的受支持
我希望在 javafx 中让标签每 0.1 秒闪烁一次。文本显示在后台运行的 ImageView gif 的顶部。我将如何去做,或者您对最佳方法有什么建议? 谢谢 最佳答案 @fabian 的解决方案
我需要测试所选项目的值以调用不同的方法,因此我编写了添加侦听器的代码,但是该代码生成语法错误 @FXML private JFXComboBox cmbComp; cmbComp.valuePrope
我正在 Javafx 中编写一个非常简单的应用程序,其中舞台上有一个带有文本框的按钮作为一个场景。现在,我想要的行为是,当我单击按钮时,我可以使用另一个按钮加载另一个场景和舞台上的一个文本框,然后删除
编辑:如果用户单击“删除”以删除 ListView 中的项目,我会弹出一个警告框。它有效,但我希望它能超越原来的舞台。它出现在我的第一台显示器上。有什么方法可以设置警报显示时的位置吗? 请注意,“所有
我想使用 JavaFX 编写一个笔画绘图应用程序。我有一个压敏绘图板,如果能够读取笔的压力和倾斜值,那就太好了。 JavaFX 有一个 API 可以处理鼠标、触摸和滑动输入,但似乎没有任何东西可以产生
我在 JavaFX 中使用条形图和折线图。当我使两个图表大小相同并将它们放在同一位置时,它们完美地相互重叠。我如何使折线图显示在条形图的顶部。 目前我已将它们的不透明度设置为 0.7,这样它们“看起来
此问题与 this 相关。现在我想为字段值等于某个值的行着色。 @FXML private TableView tv_mm_view; @FXML private Ta
我有一个程序,可以生成高度图(0-255 的整数的 2D 数组),并使用 Shape3D“Box”对象为每个“像素”构建 3D View ,其高度与其在高度图中的值成比例。这会创建一个看起来很酷的四四
我想为 JavaFX 创建上下文菜单。这是我测试过的代码。但是由于某种原因,当我右键单击树节点时没有上下文菜单。你能帮我找出我的错误吗。 import java.util.Arrays; import
我是一名优秀的程序员,十分优秀!