我使用java创建了一个控制台应用程序,并添加了一个菜单来选择用户要做什么。我使用另一个类创建了一个简单的gui,只需通过应用程序扩展它。每当用户选择启动gui时,我都需要在控制台应用程序中启动它。我该怎么做?控制台应用程序
mport java.util.Scanner;
public class ConsoleApplication {
private static LeagueManager leagueManager = new PremierLeagueManager();
public static void main(String[] args) {
//menu goes in
final Scanner scanner = new Scanner(System.in);
boolean exit = false;
String select;
loadFromFile();
do {
System.out.println("Premier League Manager");
System.out.println("=================================");
System.out.println("Please enter A to Add Football Club");
System.out.println("Please enter D to Delete Football Club");
System.out.println("Please enter S to Display Club Statistics");
System.out.println("Please enter P to Display League Table");
System.out.println("Please enter M to Add Played Match");
System.out.println("Please enter Q to Exit");
System.out.print("Please enter your choice: ");
select = scanner.nextLine();
switch (select){
case "A":
case "a" :
addFootballClub();
exit = false;
break;
case "D":
case "d":
deleteFootballClub();
exit = false;
break;
case "S":
case "s":
displayStatistics();
exit = false;
break;
case "P":
case "p":
displayLeagueTable();
exit = false;
break;
case "M":
case "m":
addPlayedMatch();
exit = false;
break;
case "Q":
case "q":
saveToFile();
System.exit(0);
exit = true;
default:
System.out.println("Invalid choice! please try again");
exit = false;
}
}while (!exit);
}
public static void addFootballClub(){
Scanner scanner = new Scanner(System.in);
boolean exit = false;
String clubType = null;
String inputClub;
图形用户界面
AnchorPane headerPane = new AnchorPane();
headerPane.setId("header-pane");
headerPane.setLayoutY(0);
headerPane.setLayoutX(0);
FileInputStream logoFile = new FileInputStream("assets/images/logo-design.png");
Image logoImage = new Image(logoFile);
ImageView logoView = new ImageView(logoImage);
logoView.setLayoutX(0);
logoView.setLayoutY(0);
HBox btnHolder = new HBox(20);
Label home = new Label("Home");
home.setId("home");
Label pointTable = new Label("Point Table");
pointTable.setId("point-table");
Label playMatch = new Label("Play Match");
playMatch.setId("play-match");
Label matches = new Label("Matches");
matches.setId("matches");
btnHolder.getChildren().addAll(home,pointTable,playMatch,matches);
btnHolder.setLayoutY(40);
btnHolder.setLayoutX(600);
FileInputStream closeFile = new FileInputStream("assets/images/close.png");
Image closeImage = new Image(closeFile);
ImageView closeView = new ImageView(closeImage);
closeView.setId("close-view");
closeView.setLayoutY(10);
closeView.setLayoutX(970);
closeView.setOnMouseClicked( e -> primaryStage.close());
headerPane.getChildren().addAll(logoView,btnHolder,closeView);
AnchorPane contentPane = new AnchorPane();
contentPane.setId("content-pane");
contentPane.setLayoutX(0);
contentPane.setLayoutY(100);
AnchorPane textPane = new AnchorPane();
textPane.setId("text-pane");
Text description = new Text("The Premier League is the top tier of England's football pyramid," +"\n"+
" with 20 teams battling it out for the honour of being crowned English champions.\n" +
"\n" +
"\n"+
暂无答案!
目前还没有任何答案,快来回答吧!