トップ 差分 一覧 ソース 置換 検索 ヘルプ PDF RSS ログイン

JavaFXの簡単なサンプル

http://naokirintechnews.hatenablog.com/entry/2012/04/15/124103

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;

public class JavaFXMemo extends Application {
  
  private Scene scene;
  private VBox vbox;
  
  private TextArea textArea;
  private TextField commandField;
  private Button commandButton;
  private HBox commandArea;
  
  public static void main(String[] args){
    Application.launch(JavaFXMemo.class, args);
  }
  
  @Override
  public void start(Stage stage) {
    // シーングラフとルートオブジェクトの生成
    vbox = new VBox();
    scene = new Scene(vbox);
    
    // テキストエリア、テキストフィールド、ボタンの設定
    textArea = new TextArea();
    commandField = new TextField();
    commandButton = new Button("Command");
    commandArea = new HBox();
    
    // テキストエリアとコマンドフィールドの大きさをSceneの大きさに合わせて変更するようにする
    textArea.minHeightProperty().bind(scene.heightProperty().subtract(commandArea.heightProperty()));
    commandField.minWidthProperty().bind(scene.widthProperty().subtract(commandButton.widthProperty()));
    
    // それぞれのオブジェクトを追加
    commandArea.getChildren().addAll(commandField, commandButton);
    vbox.getChildren().addAll(textArea, commandArea);
    
    // コマンドの実行
    commandButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
          if (commandField.getText().equals("quit"))
            Platform.exit();
        }
    });
    
    // Stageの設定
    stage.setScene(scene);
    stage.setTitle("JavaFXMemo");
    stage.setWidth(1024); stage.setHeight(700);
    stage.show();
  }
  
  @Override
  public void stop(){
    System.out.println("アプリケーションを終了します...");
  }
}

[カテゴリ: プログラミング言語 > JavaFX]

[通知用URL]



  • Hatenaブックマークに追加
  • livedoorクリップに追加
  • del.icio.usに追加
  • FC2ブックマークに追加

最終更新時間:2013年10月29日 22時57分30秒