私は現在、学校にいますが、キーボードのボタンを1つだけ書いて解決策を考案しています。主なタスクは、レポートを作成することですが、プロトタイプを作成する必要もあります。それが私が立ち往生している場所です。 私はa-å(ノルウェー語の文字)からすべてのボタンを使ってJavaFXを作っており、ランダムなボタン(キーボードのgキーと言う)を選んで、プッシュするたびに次の文字に移動します。ボタンをダブルクリックすると、文字をテキストボックスに印刷し、次のクリックは次の行に移動します。そうすれば、簡単なテキストメッセージを書くことができます。1つのボタンで書く
「Gキー」スイッチをさまざまなボタンから作成する方法と、テキストフィールドに印刷する方法については、今は本当に固まっています。また、私はプログラミングとJavaFXにはかなり新しいです、そして、どんなばかげた質問でもお詫び申し上げます。また、JavaFXがこれを行う最も簡単な方法であるかどうかはわかりませんが、私はそれをよく知っているので、それを選択してください。これまで
マイコード: sample.fxml:
<GridPane fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="2">
<Button text="A" fx:id="pushed" onAction="#write"/>
<Button text="B" />
<Button text="C"/>
<Button text="D"/>
<Button text="E"/>
</HBox>
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="3">
<Button text="F"/>
<Button text="G"/>
<Button text="H"/>
<Button text="I"/>
<Button text="J"/>
<Button text="K"/>
</HBox>
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="4"></HBox>
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="5">
<Button text="R"/>
<Button text="S"/>
<Button text="T"/>
<Button text="U"/>
<Button text="V"/>
<Button text="X"/>
</HBox>
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="6">
<Button text="Y"/>
<Button text="Z"/>
<Button text="Æ"/>
<Button text="Ø"/>
<Button text="Å"/>
</HBox>
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="7">
<Button text="Space"/>
<Button text="."/>
</HBox>
</GridPane>
Controller.java:
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
public class Controller {
public void write(ActionEvent event){
}
}
Main.java:ここ
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
通常のタスクではなくToggleButtonsを使用すると、タスクをすぐに簡略化できます。 –
キーボード入力は "anykey"というidと "setOnMouseClicked"という1つの "any key"ボタンを作るので、MouseEventとisgetの 'getClickCount'を得ることができます。これで、ダブルクリックを検出できます。ボタンは出力として使用できます。ダブルクリックするとどのキーが使用されますか。トグルボタン(またはラジオボタン)を使用することもできます。 –