我正在尝试实现一个简单的JavaFX GUI - 意思是几个按钮,一个文本区域,几个圆圈(作为灯光)和一些标签。
请注意,尚未创建这些项目的任何功能。因此所有这些项目基本上是空心的。请注意,这是我的第一个JavaFX应用程序(我一直在Swing中工作)。
因此,在我的i7笔记本电脑上运行Eclipse没有任何问题,运行完美无缺。当我尝试在目标机器上运行它时(下面的规范)我得到大约15秒长的无响应窗口。一旦gui出现,对窗口中任何元素的任何点击都会导致~10秒的CPU峰值达到50%。
再一次,任何按钮或灯光或文本区域后面都没有代码。 JavaFX是不是意味着要在这样一个低端系统上?
规格: Windows Embedded 32bit(6.1) 英特尔凌动E680 @ 1.6Ghz 2GB Ram DX11 Atom E6xx嵌入式媒体和图形
如果有人需要,代码如下。
主:
public static void main(String[] args)
{
// Initialize GUI
gui = RecorderFXApplication.getGUIInstance();
guiCtrl = gui.getFXMLController();
}
应用:
public class RecorderFXApplication extends Application
{
/**
* Standard error logger for log4j2
*/
static Logger errorLog = LogManager.getLogger(RecorderFXApplication.class.getName());
private static RecorderFXApplication instance = null;
private FXMLLoader fxmlLoader;
public RecorderFXApplication()
{
super();
}
@Override
public void start(Stage primaryStage) throws Exception
{
fxmlLoader = new FXMLLoader(getClass().getResource("/RecorderGUI.fxml"));
try
{
Pane root = (Pane) fxmlLoader.load();
Scene scene = new Scene(new Group(root));
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.titleProperty().set("Faceboss Database Recorder");
instance = this;
} catch (IOException exception)
{
errorLog.error("Error loading fxml for view: " + exception);
}
}
@Override
public void stop() throws Exception
{
super.stop();
System.exit(0);
}
/**
* @return the instance
*/
public static RecorderFXApplication getGUIInstance()
{
if (instance == null)
{
new Thread(new Runnable()
{
@Override
public void run()
{
Application.launch(RecorderFXApplication.class);
}
}).start();
}
while (instance == null)
{
try
{
Thread.sleep(1);
} catch (InterruptedException e)
{
errorLog.error("Error getting instance " + e);
}
}
return instance;
}
public RecorderFXController getFXMLController()
{
while (fxmlLoader.getController() == null)
{
try
{
Thread.sleep(1);
} catch (InterruptedException e)
{
errorLog.error("Error getting controller " + e);
}
}
return fxmlLoader.<RecorderFXController> getController();
}
}
控制器:
public class RecorderFXController implements Initializable
{
/**
* Standard error logger for log4j2
*/
static Logger errorLog = LogManager.getLogger(RecorderFXController.class.getName());
@FXML
private TextArea logWindow;
@FXML
private Button startRecButton;
@FXML
private Button stopRecButton;
@FXML
private Button pauseRecButton;
@FXML
private Button exportButton;
@FXML
private Circle redLight;
@FXML
private Circle yellowLight;
@FXML
private Circle greenLight;
@Override
public void initialize(URL arg0, ResourceBundle arg1)
{
}
}