这是我的项目,我将javafxml与我的代码一起使用,但不起作用 什么是错误的帮助我快速帮助我,我想通过gui向用户显示具有文本问候的标签。下面是代码:
package tacticalchaos;
import Project.*;
import java.util.*;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class TacticalChaos {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getclass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Ways way = new Ways();
Scanner in = new Scanner(System.in);
System.out.println("Choose (1) For console\n(2) For GUI: ");
switch (in.nextInt()) {
case 1:
Console w = new Console();
way = w;
break;
case 2: {
Gui ww = new Gui();
way = ww;
launch(args);
break;
}
}
way.Print1("hello");
}
//controller class
i want to show for user by gui the label which has text hello
package Project;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Scanner;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
/**
* FXML Controller class
*
* @author Asus
*/
public class GuifxController extends Ways implements Initializable {
@FXML
private Label chinfo1;
private String a,inf1;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url,ResourceBundle rb) {
chinfo1.setText("");
}
public void Print1(Object... obj) {
inf1 = "";
for (Object c : obj) {
inf1 += c.toString();
}
inf1 += "\n";
System.out.print(inf1);
l.setText(inf1);
}}