gpt4 book ai didi

java - 单击两个不同的复选框(一个接着另一个)在 netbeans 中调用两个不同的窗口会出现异常

转载 作者:行者123 更新时间:2023-12-01 13:08:35 25 4
gpt4 key购买 nike

这是复选框的两个函数

复选框:ActiveBox

private void Active_BoxActionPerformed(java.awt.event.ActionEvent evt) {
if (Active_Box.isSelected() == true) {
Active_Link.main(args);
}
}

复选框:SQLBox

private void SQL_boxActionPerformed(java.awt.event.ActionEvent evt) {
if (ESC_box.isSelected() == true) {
ESC.main(args);
}
}

Active.java

public class Active extends Application { 
private final Node rootIcon=null;

TreeItem<String> rootNode = new TreeItem<String>("My Workflows");

public static void main(String[] args) {
launch(args);
}

public void start(Stage stage) {
rootNode.setExpanded(true);
BufferedReader reader = null;

try {
reader = new BufferedReader(new FileReader("D:\\onlyForms.txt"));

String line=null;

while ((line = reader.readLine()) != null) {
if (line.indexOf("Checking") >= 0) {
String next=reader.readLine();
if(next.contains("Passed_qualification ")) {
TreeItem<String> depNode = new TreeItem<String>(line)
depNode.setExpanded(false);
TreeItem<String> depNode1 = new TreeItem<String>(next);
depNode.getChildren().add(depNode1);
String next1=reader.readLine();
TreeItem<String> depNode2 = new TreeItem<String>(next1);
depNode.getChildren().add(depNode2);
rootNode.getChildren().add(depNode);
}
if(next.contains("Failed_qualification ")) {
TreeItem<String> depNode = new TreeItem<String>(line);
depNode.setExpanded(false);
TreeItem<String> depNode1 = new TreeItem<String>(next);
depNode.getChildren().add(depNode1);
String next1=reader.readLine();
TreeItem<String> depNode2 = new TreeItem<String>(next1);
depNode.getChildren().add(depNode2);
rootNode.getChildren().add(depNode);
}
stage.setTitle("Escalations");
VBox box = new VBox();
final Scene scene = new Scene(box, 500, 500);
scene.setFill(Color.LIGHTGRAY);
box.setStyle("-fx-font: 18 arial;");
TreeView<String> treeView = new TreeView<String>(rootNode);
box.getChildren().add(treeView);
stage.setScene(scene);
stage.show();
}
}

SQL.java

public class SQL extends Application { 
static String str=null;

static String next_line=null;

static BufferedReader br;

private final Node rootIcon;

public static void main(String[] args) throws IOException {
launch(args);

}

public SQL() {
this.rootIcon = null;
}

public void start(Stage stage) throws IOException {
rootNode.setExpanded(true);

BufferedReader reader=null;

try
{
FileInputStream f=new FileInputStream("D:\\SQL\\SQL_XML_TXT.txt");
reader = new BufferedReader(new InputStreamReader(f));
String line=null;
while ((line = reader.readLine()) != null) {
if (line.indexOf("TID") >=0) {
String next1=reader.readLine();
String next2=reader.readLine();
String next3=reader.readLine();
String next4=reader.readLine();
String next5=reader.readLine();
String next6=reader.readLine();
String next7=reader.readLine();

String time_date=SQL.GetTime(br);

if(((next7.indexOf("OK"))<0)) {
if(((next7.indexOf("SQL Trace Log- ON"))<0)) {
TreeItem<String>depNode=new TreeItem<String>(line);
depNode.setExpanded(false);
TreeItem<String> depNode1 = new TreeItem<String>(next1);
depNode.getChildren().add(depNode1);

TreeItem<String> depNode2=new TreeItem<String>(next2);

depNode1.getChildren().add(depNode2);

TreeItem<String> depNode3=new TreeItem<String>(next3);
depNode1.getChildren().add(depNode3);

TreeItem<String> depNode4=new TreeItem<String>(next4);

depNode1.getChildren().add(depNode4);

TreeItem<String> depNode5=new TreeItem<String>(next5);
depNode1.getChildren().add(depNode5);

TreeItem<String> depNode6=new TreeItem<String>(next6);

depNode1.getChildren().add(depNode6);

TreeItem<String> depNode7=new TreeItem<String>(next7);

depNode1.getChildren().add(depNode7);
rootNode.getChildren().add(depNode);
}

}
}
}

}
stage.setTitle("Escalations");
VBox box = new VBox();
final Scene scene = new Scene(box, 500, 500);
scene.setFill(Color.LIGHTGRAY);
box.setStyle("-fx-font: 18 arial;");
TreeView<String> treeView = new TreeView<String>(rootNode);
box.getChildren().add(treeView);
stage.setScene(scene);
stage.show();
}
}

当我单击两个复选框时,第一个窗口将打开,当我单击另一个复选框时,它会引发以下异常

"Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Application launch must not be called more than once at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:137) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:118) at javafx.application.Application.launch(Application.java:241)

最佳答案

不要尝试多次调用javafx.application.Application.launch。这会导致你的异常。如果您想创建一个新窗口,只需创建一个新的 Stage 并将新内容添加到此阶段(因为您是从 Swing 创建窗口,所以您必须从 JFX 线程执行此操作;请参阅最后的代码片段):

Stage stage = new Stage();
// add your content here
stage.show();

如果您仍然希望将 SQLActive 作为应用程序的可能入口点,我建议编写基本上与您的 start 相同的方法 方法(减去 Stage 部分),但返回 Scene 对象,例如像这样的东西:

public class Active extends Application {

public static Scene createScene() {
Scene scene = //... insert your code here

return scene;
}

@Override
public void start(Stage stage) throws Exception {
stage.setScene(createScene());
stage.show();
}

public static void main(String[] args) {
launch(args);
}

}

并像这样更改 CheckBox 函数:

private void Active_BoxActionPerformed(java.awt.event.ActionEvent evt) {
if (Active_Box.isSelected() == true) {
Platform.runLater(() -> { // invoke "Runnable" from JFX thread
Stage stage = new Stage();
stage.setScene(Active.createScene());
stage.show();
});
}
}

并对 SQL 部分执行相同的操作。

如果您不需要 SQLActive 作为入口点,那么您当然不需要扩展 Application 。 .

关于java - 单击两个不同的复选框(一个接着另一个)在 netbeans 中调用两个不同的窗口会出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23077072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com