`void carregar(){
String z = board.promptText("Какое имя нужно сделать для записи?");
if (z == null || z.isEmpty()) {
return;
PositionTrace novoModel = new PositionTrace(model.blackCount, model.whiteCount, model.linha, model.coluna);
Board novoTabuleiro = new Board(quemJoga(), novoModel.linha, novoModel. coluna, 60);
novoTabuleiro.setBackgroundProvider(this::background);
novoTabuleiro.setIconProvider(this::icon);
novoTabuleiro.addMouseListener(this::click);
novoTabuleiro.addAction("Novo Jogo", this::action);
novoTabuleiro .addAction("Алеаторио", this::aleatorio);
novoTabuleiro.addAction("Гравар", this::gravar);
novoTabuleiro.addAction("Carregar", this::carregar);
novoModel.load(z);
novoTabuleiro.setTitle(quemJoga());
novoTabuleiro.open();
}
void load(String fileName) {
Код: Выделить всё
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file);
jogamBrancas = Boolean.parseBoolean(scanner.nextLine());
linha = Integer.parseInt(scanner.nextLine());
coluna = Integer.parseInt(scanner.nextLine());
blackCount = Integer.parseInt(scanner.nextLine());
whiteCount = Integer.parseInt(scanner.nextLine());
positionWhities = new Position[whiteCount];
positionBlackies = new Position[blackCount];
for (int i = 0; i < whiteCount; i++) {
int line = Integer.parseInt(scanner.nextLine());
int col = Integer.parseInt(scanner.nextLine());
positionWhities[i] = new Position(line, col);
}
for (int i = 0; i < blackCount; i++) {
int line = Integer.parseInt(scanner.nextLine());
int col = Integer.parseInt(scanner.nextLine());
positionBlackies[i] = new Position(line, col);
}
scanner.close();
System.out.println("Jogo carregado com sucesso de " + fileName);
} catch (FileNotFoundException e) {
System.out.println("Erro: Arquivo não encontrado.");
} catch (Exception e) {
System.out.println("Erro ao carregar o arquivo: " + e.getMessage());
}
}`
Подробнее здесь: https://stackoverflow.com/questions/792 ... e-carregar