현재 Textadventure 작업을하고 있으며 콘솔에서 Scenebuilder를 사용하여 JavaFX로 이동하기로 결정했습니다. 출력용 TextView 및 입력 용 TextField를 사용하고 있습니다. - 의사 결정과 스토리에 더 방법에 대한 더 Eventfilters을TextField에 대한 대기 입력 메소드를 효율적으로 구현하는 방법은 무엇입니까? (JavaFX)
public class Story implements Initializable {
public Button startButton;
public TextArea textArea;
public TextField textField;
public EventHandler mainplot;
//On startButton pressed
public void startGame() {
setEventFilters();
begin();
}
public void begin() {
print("Welcome to the Adventure."); //print is a method for appending String to textArea
print("You wake up in your room.");
print("Fresh air blows through your window.");
print("You get up. What do you want to do?");
print("1. Drink from the magical can.");
print("2. Go outside.");
textField.addEventFilter(ActionEvent.ACTION, mainplot);
}
public void magicalCan() {
...
}
public void goOutside() {
...
}
public void setEventFilters() {
//mainplotFilter
mainplot = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e){
if(textField.getText().equals("1")) {
textField.removeEventFilter(ActionEvent.ACTION, mainplot);
magicalCan();
}
if(textField.getText().equals("2")) {
textField.removeEventFilter(ActionEvent.ACTION, mainplot);
goOutside();
}
}
};
}
코드가 같은 방식으로 계속 : 이 내 코드 모습입니다. 이제 let's 내가 스토리 내에서 여러 enterkey 입력을 추가 할 말 :
public void begin() {
print("Welcome to the Adventure.");
//wait for enter to continue
print("You wake up in your room.");
print("Fresh air blows through your window.");
print("You get up. What do you want to do?");
//wait for enter to continue
print("1. Drink from the magical can.");
print("2. Go outside.");
textField.addEventFilter(ActionEvent.ACTION, mainplot);
}
이벤트 핸들러 또는 모든 스토리의 방법을 통해 사용할 수있는 waitForEnterkey() 메소드를 구현하는 가장 효율적인 방법은 무엇입니까?
왜 20-30 개의 이벤트 처리기가 필요합니까? 스토리 라인의 상태를 기반으로 의사 결정을 내릴 수있는 하나의 핸들러가 더 나은 접근 방법입니다. – Geoff
시도하기 전에 간단한'JavaFX' 튜토리얼을 수행하십시오. [여기] (http://tutorials.jenkov.com/javafx/textfield.html)를 시작하십시오. 'Textfield'가 어떻게 작동하는지 이해하지 못합니다. – Sedrick
나는 내 질문을 명확히했다. 한번보세요. – Andrenergy