Этот класс является основным классом, который содержит то, что мне нужно для запуска в симуляции, которую он будет отображать на консоли людей, поднимающихся и спускающихся в лифте.
package Main;
import java.io.IOException;
import java.util.Random;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import parts.Building;
import parts.Simulation;
import people.Developers;
import people.Employee;
import people.Person;
import view.TextView;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("SimView.fxml"));
loader.setController(new InterfaceController());
Parent root = loader.load();
Scene scene = new Scene(root, 400, 400);
primaryStage.setTitle("Simulator");
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
//the random number generator
Random rnd = new Random(2); //set the seed for random so we get the same random numbers
//Generate the initial employees and developers that are in the building
int employees = 5;
int developers = 5;
Simulation simulation = new Simulation(rnd);
Building building = simulation.getBuilding();
int floors = building.getNumFloors();
for (int i = 0; i < developers; i++) {
int n = ((floors + 1)/2) + rnd.nextInt(floors - (floors/2) - 1); //generate numbers from numfloors/2 to numfloors (top half of building)
String id = "D" + i;
Person dev = new Developers(id, 0, n, simulation, rnd);
building.arrive(dev);
}
for (int i = 0; i < employees; i++) {
int n = 1 + rnd.nextInt(floors - 1); //generate numbers from 1 to number of floors
String id = "E" + i;
Person emp = new Employee(id, 0, n, simulation, rnd);
building.arrive(emp);
}
//set up the text view to display text in the console
TextView v = new TextView(simulation);
for (int i = 0; i < 30; i++) { //number of ticks
v.show();
simulation.tick();
}
launch(args);
}
}
Это F XML это то, что смутило меня: как заставить кнопку запуска запускать программу при нажатии и как ее остановить? Я хотел бы, чтобы кнопки «Пуск» и «Стоп» работали.
package Main;
import javafx.fxml.FXML;
import java.util.*;
public class InterfaceController {
public InterfaceController() {
}
@FXML
public void quitPressed() {
System.exit(0);
}
@FXML
public void StartPressed() {
}
@FXML
public void StopPressed() {
}
}
Если есть простой способ, мы будем благодарны за ваше внимание и спасибо за ваши усилия.