- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从 youtube 上完成了这个教程,我的代码与教程相同,但我使用 Scenebuilder 做了正确的 fxml。 这是代码:https://github.com/AlmasB/FXTutorials/tree/master/src/com/almasb/calc 我有相同的主控、相同的 Controller 和相同的型号.. 当我尝试编译时,它对我说:
`Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1394438858.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at application.Main.start(Main.java:12)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1252716230.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1775282465.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/21202996.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/2040495657.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1558600329.run(Unknown Source)
... 1 more
Exception running application application.Main
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Parent;
这是我的主要:
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("view/Calculatorview.fxml"));
// Parent root = FXMLLoader.load(getClass().getResource("view/Calculatorview.fxml"));
AnchorPane root = (AnchorPane) loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
这是我的 fxml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.embed.swing.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="640.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<AnchorPane prefHeight="600.0" prefWidth="700.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<SplitPane dividerPositions="0.19063545150501673" layoutX="149.0" layoutY="32.0" orientation="VERTICAL" prefHeight="600.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<TextField alignment="CENTER_RIGHT" prefHeight="73.0" prefWidth="638.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font>
<Font size="47.0" />
</font>
</TextField>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="515.0" prefWidth="498.0">
<children>
<GridPane layoutX="90.0" layoutY="116.0" prefHeight="319.0" prefWidth="638.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="116.0" minWidth="10.0" prefWidth="95.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="116.0" minWidth="10.0" prefWidth="95.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<effect>
<Blend />
</effect>
<children>
<Button mnemonicParsing="false" onAction="#processOperator" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #EE543A; -fx-text-fill: #FFFFFF;" text="=" GridPane.columnIndex="7" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="620.0" layoutY="395.0" mnemonicParsing="false" onAction="#processOperator" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #EE543A; -fx-text-fill: #FFFFFF;" text="+" GridPane.columnIndex="7" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="620.0" layoutY="299.0" mnemonicParsing="false" onAction="#processOperator" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #EE543A; -fx-text-fill: #FFFFFF;" text="-" GridPane.columnIndex="7" GridPane.rowIndex="2">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="620.0" layoutY="203.0" mnemonicParsing="false" onAction="#processOperator" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #EE543A; -fx-text-fill: #FFFFFF;" text="×" GridPane.columnIndex="7" GridPane.rowIndex="1">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="620.0" layoutY="107.0" mnemonicParsing="false" onAction="#processOperator" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #EE543A; -fx-text-fill: #FFFFFF;" text="÷" GridPane.columnIndex="7">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="532.0" layoutY="395.0" mnemonicParsing="false" prefHeight="70.0" prefWidth="76.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="C" GridPane.columnIndex="4" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="358.0" layoutY="395.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="0" GridPane.columnIndex="5" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="362.0" layoutY="395.0" mnemonicParsing="false" prefHeight="69.0" prefWidth="88.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="M-" GridPane.columnIndex="4">
<font>
<Font size="28.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="e" GridPane.columnIndex="1" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="1/x" GridPane.columnIndex="3" GridPane.rowIndex="4">
<font>
<Font name="System" size="28.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="√" GridPane.columnIndex="3" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="MC" GridPane.columnIndex="3" GridPane.rowIndex="2">
<font>
<Font name="System" size="28.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="M+" GridPane.columnIndex="3" GridPane.rowIndex="1">
<font>
<Font size="27.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="x²" GridPane.columnIndex="2" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="tan" GridPane.columnIndex="2" GridPane.rowIndex="2">
<font>
<Font name="System" size="28.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="sin" GridPane.columnIndex="2" GridPane.rowIndex="1">
<font>
<Font name="System" size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="xʸ" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="log" GridPane.rowIndex="2">
<font>
<Font name="System" size="28.0" />
</font>
</Button>
<Button graphicTextGap="0.0" layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="cos" GridPane.columnIndex="2">
<font>
<Font name="System" size="26.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text=")">
<font>
<Font size="30.0" />
</font>
</Button>
<Button alignment="CENTER" layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="x³" GridPane.columnIndex="2" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="98.0" layoutY="11.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="(" GridPane.rowIndex="1">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="64.0" prefWidth="95.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="3" GridPane.columnIndex="6" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="2" GridPane.columnIndex="5" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="64.0" prefWidth="96.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="6" GridPane.columnIndex="6" GridPane.rowIndex="2">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="64.0" prefWidth="98.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="9" GridPane.columnIndex="6" GridPane.rowIndex="1">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="8" GridPane.columnIndex="5" GridPane.rowIndex="1">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" prefHeight="64.0" prefWidth="96.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="±" GridPane.columnIndex="5">
<font>
<Font size="29.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="58.0" prefWidth="76.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="1" GridPane.columnIndex="4" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="4" GridPane.columnIndex="4" GridPane.rowIndex="2">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="5" GridPane.columnIndex="5" GridPane.rowIndex="2">
<font>
<Font size="35.0" />
</font>
</Button>
<Button layoutX="10.0" layoutY="11.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="7" GridPane.columnIndex="4" GridPane.rowIndex="1">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="619.0" layoutY="395.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="81.0" style="-fx-background-color: #EE543A; -fx-text-fill: #FFFFFF;" text="\%" GridPane.columnIndex="6">
<font>
<Font size="29.0" />
</font>
</Button>
<Button mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="π" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="462.0" layoutY="202.0" mnemonicParsing="false" onAction="#processNumpad" prefHeight="64.0" prefWidth="95.0" style="-fx-background-color: #9E9D9B; -fx-text-fill: #FFFFFF;" text="." GridPane.columnIndex="6" GridPane.rowIndex="4">
<font>
<Font size="30.0" />
</font>
</Button>
<Button graphicTextGap="0.0" layoutX="172.0" layoutY="10.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="cosh" GridPane.columnIndex="1">
<font>
<Font name="System" size="22.0" />
</font>
</Button>
<Button layoutX="172.0" layoutY="74.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="sinh" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font size="25.0" />
</font>
</Button>
<Button layoutX="172.0" layoutY="138.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="tanh" GridPane.columnIndex="1" GridPane.rowIndex="2">
<font>
<Font name="System" size="24.0" />
</font>
</Button>
<Button layoutX="91.0" layoutY="266.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="10ʸ" GridPane.columnIndex="1" GridPane.rowIndex="3">
<font>
<Font size="30.0" />
</font>
</Button>
<Button layoutX="253.0" layoutY="74.0" mnemonicParsing="false" prefHeight="96.0" prefWidth="92.0" style="-fx-background-color: #60646D; -fx-text-fill: #FFFFFF;" text="MR" GridPane.columnIndex="3">
<font>
<Font size="28.0" />
</font>
</Button>
</children>
</GridPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</children>
</fx:root>
新主线: structure
最佳答案
好吧。我尝试使用 Java 1.8 设置我的环境,并尝试了提供的链接中的教程。这就是我所做的。
上面之后,我在 eclipse 中创建了一个新的 Java 项目。我右键单击该项目并创建了两个源文件夹,即
src/main/java
src/main/resources
然后我右键单击 src/main/java 并创建新包并将其命名为 application。在应用程序下,我创建了 4 个 java 类,并复制了教程链接中的内容。我确实修改了每个 java 文件顶部的包以仅反射(reflect)应用程序。
这是java类
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/ui.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
public class Controller {
@FXML
private Text output;
private long number1 = 0;
private String operator = "";
private boolean start = true;
private Model model = new Model();
@FXML
private void processNumpad(ActionEvent event) {
if (start) {
output.setText("");
start = false;
}
String value = ((Button)event.getSource()).getText();
output.setText(output.getText() + value);
}
@FXML
private void processOperator(ActionEvent event) {
String value = ((Button)event.getSource()).getText();
if (!"=".equals(value)) {
if (!operator.isEmpty())
return;
operator = value;
number1 = Long.parseLong(output.getText());
output.setText("");
}
else {
if (operator.isEmpty())
return;
output.setText(String.valueOf(model.calculate(number1, Long.parseLong(output.getText()), operator)));
operator = "";
start = true;
}
}
}
型号
package application;
public class Model {
public long calculate(long number1, long number2, String operator) {
switch (operator) {
case "+":
return number1 + number2;
case "-":
return number1 - number2;
case "*":
return number1 * number2;
case "/":
if (number2 == 0)
return 0;
return number1 / number2;
}
System.out.println("Unknown operator - " + operator);
return 0;
}
}
和 ui.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.beans.property.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.paint.Color?>
<VBox spacing="10" alignment="CENTER" prefWidth="300" prefHeight="300" fx:controller="application.Controller" xmlns:fx="http://javafx.com/fxml">
<fx:define>
<Font fx:id="FONT" size="18" />
</fx:define>
<StackPane alignment="CENTER">
<Rectangle fill="TRANSPARENT" stroke="GRAY" width="230" height="50" />
<Text fx:id="output" font="$FONT" />
</StackPane>
<HBox spacing="10" alignment="CENTER">
<Button text="7" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="8" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="9" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="/" prefWidth="50" font="$FONT" onAction="#processOperator" />
</HBox>
<HBox spacing="10" alignment="CENTER">
<Button text="4" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="5" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="6" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="*" prefWidth="50" font="$FONT" onAction="#processOperator" />
</HBox>
<HBox spacing="10" alignment="CENTER">
<Button text="1" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="2" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="3" prefWidth="50" font="$FONT" onAction="#processNumpad" />
<Button text="-" prefWidth="50" font="$FONT" onAction="#processOperator" />
</HBox>
<HBox spacing="10" alignment="CENTER">
<Button text="0" prefWidth="110" font="$FONT" onAction="#processNumpad" />
<Button text="=" prefWidth="50" font="$FONT" onAction="#processOperator" />
<Button text="+" prefWidth="50" font="$FONT" onAction="#processOperator" />
</HBox>
</VBox>
我遇到了 Java 源库(引用 JRE)和 jfxrt.jar 文件的问题。所以我做了以下事情
添加上述代码后,代码已解决,没有任何问题。
请记住,我将 ui.fxml 放置在 src/main/resources 文件夹下。因此,当我最初将项目作为 Java 应用程序 运行时,它会提示并给出与您所面临的相同的异常。所以我将“ui.fxml”更改为“/ui.fxml”,然后,我看到了计算器。
Parent root = FXMLLoader.load(getClass().getResource("/ui.fxml"));
请参阅下面的屏幕截图,希望这些步骤有所帮助。
关于java - 在 main 中加载 fxml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33683302/
因此,当使用“智能”时,当我想创建一个类时,它还会创建另外两个函数(不确定我是否正确调用了它们): class main { private: /* data */ public: m
我确实知道 C/C++ 和 Java 中使用的 main() 方法,但由于 main() 是用户定义的(因为 main() 中的代码是由用户定义的,它不能是预定义的方法) & 在 C/C++ 中,ma
这个问题在这里已经有了答案: What is a NullPointerException, and how do I fix it? (12 个答案) 关闭 7 年前。 我意识到这是一个常见错误,
您好,我是 jquery 和 javascript 的新手。我想做的是我有 3 个独立的 Main-Divs ex main-div1, main-div2, main-div-3 它们都是一个大盒子
我知道以前曾有人问过有关此错误的问题,但我的情况与其他人不同。我正在编写计算数据集的平均值、方差和标准差的代码。编译代码时我没有收到任何错误,但是当我尝试运行代码时,我收到如下错误: Exceptio
这个问题已经有答案了: What should main() return in C and C++? (19 个回答) Why is the type of the main function in
无效的输入流不起作用 - 每次我给出负的月份值时,它都会返回此异常。 代码: import java.util.Scanner; public class Main { public stat
我在 main() 中调用 main(),递归 10 次。现在,在使用 gdb (bt/backtrace) 进行调试时,我没有看到 main() 的多个帧。为什么? #include int mai
我有一个类 - A - 没有方法,只有主要方法。 在其他类(class) - B - 我需要调用那个 main.做什么最好?从使用的资源、时间和功耗以及效率来看? 从类 A 创建一个“a”对象并执行
鉴于 documentation以及对 earlier question 的评论,根据要求,我制作了一个最小的可重现示例,演示了这两个语句之间的区别: my %*SUB-MAIN-OPTS = :na
我有一个在 main 中声明并初始化的数组,名为 Edges。 我还在 main 中声明了一些访问名为 Edges 的数组的函数。 代码编译并运行。 为什么它有效?我认为 main 中声明的变量不是全
如果定义内容主要部分的最具语义性和可访问性的方式是标准,那么使用 ARIA 地标似乎是多余的元素。正在添加 role="main"到元素真的有必要吗? 最佳答案 并非所有现代浏览器都已经映射了 ari
我是 C 语言的新手(6 小时前开始),我知道有大量的在线引用资料,我应该(并且将会)详细查看,但现在,我有紧急情况需要帮助。我有一个包含以下文件的项目文件夹: boundary_val.c boun
我正在审查许多不同的 Java 程序,并试图弄清楚如何只更新一次而不是两次更新对程序名称的引用。有没有办法在单个终端命令中使用变量? :S 我试图改进的命令是这样的形式: javac Main.jav
我已经创建了一个工作线程, Thread thread= new Thread(runnable); thread.start(); 我在工作线程中打印这个; Log.d("SessionTh
import java.awt.*; import java.awt.event.*; import java.io.*; import java.lang.*; public class Main
这是我的 Main.java,它位于服务器套接字“get().logger().tag();”之后的部分我已经在实例中添加了所有这些,我真的不确定它出了什么问题。 public class Main
我在 http://www.hackerearth.com/problem/algorithm/roys-life-cycle/ 上测试了我的程序。但是,我总是收到错误:在类 ActivityTime
我想要一个脚本来运行从模块导出的子例程,导出的子程序在脚本中作为 MAIN 运行。该子例程做了我想做的所有事情,除了它返回结果而不是打印它。 RUN-MAIN 似乎实现了我的大部分目标,但我不确定如何
java中有什么具体原因吗,main方法应该是小写字母 是的“主要”和“主要” 编译完成 public class ManiMethod { public static void main(S
我是一名优秀的程序员,十分优秀!