忍者ブログ

からすまる日誌

実習問題31 転記ボタン

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

実習問題31 転記ボタン

実習問題31
 
クラスBorderPaneの説明書きは幸いすぐ見つかった
  
  
問題はこのBorderPaneとVboxをどう組み合わせるかにある
  
--->Exe31.java
 
package application;
import javafx. application.Application;
import javafx.event.ActionEvent;
import javafx. scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx. stage.Stage;
 
public class EXE31 extends Application {
 
 public static void main(String[] args) {
   launch(args);
 }
 
 @Override
 public void start(Stage myStage) {
  Label l1;//Label型変数l1を宣言
  //l1 = new Label("ここに文字を転記");//Labelオブジェクトを生成し変数に代入
  TextField tf1 = new TextField("文字入力できます");
  Button b1 = new Button("名前を入力してクリック");//Buttonオブジェクトを生成し変数に代入
  Button b2 = new Button("削除");
  l1 = new Label("");//はじめはからっぽ
 
  //BorderPane pane = new BorderPane();//GridPaneオブジェクトを生成し変数に代入。Gridpaneはどんどん格子型形
  VBox pane2 = new VBox();
  pane2.getChildren().addAll(tf1,b1,b2,l1);
 
  //関数
 
  //転記ボタン
  b1.setOnAction((ActionEvent event)->{
   System.out.println(tf1.getText());
   String hoge = tf1.getText();
   l1.setText(hoge+"さん、こんにちは!");
  });
  //削除ボタン
  b2.setOnAction((ActionEvent event)->{
   tf1.setText("");
   l1.setText("");
  });
  
  Scene scene = new Scene(pane2,350,350);//シーンのサイズ
 
  myStage.setTitle("Exe19");
  myStage.setScene(scene);
  myStage.show();
 }
}
  
  
ただこれは複合レイアウトの練習だったのですよ。どうやら。
→すると?
→ヒント:
ここまではあっている。このVboxを入れ子でBorderPaneのtopに入れる。
centerにl1だろうな。

i+""
とするとストリング型に強制的にできるよ
よくやる手らしいよ 

Vboxの部分
 

さて入れ子にやっとできたよ 
  
package application;
import javafx. application.Application;
import javafx.event.ActionEvent;
import javafx. scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx. stage.Stage;
public class EXE31 extends Application {
 public static void main(String[] args) {
   launch(args);
 }
 @Override
 public void start(Stage myStage) {
  Label l1;//Label型変数l1を宣言
  l1 = new Label("");//はじめはからっぽ
  TextField tf1 = new TextField("文字入力できます");
  Button b1 = new Button("名前を入力してクリック");
  Button b2 = new Button("削除");
  VBox pane2 = new VBox();
  pane2.getChildren().addAll(tf1,b1,b2);//まずここでVboxのpaneを作っていれる
  BorderPane pane = new BorderPane();//こっちがborderpane
  pane.setStyle("-fx-background-color:lightgray;");
  pane.setTop(pane2);//borderpaneのtopにVboxのなかみをそのまま入れる
  //pane.setBottom(clearB);
  pane.setCenter(l1);//centerにl1を入れる
  //関数
  //転記ボタン
  b1.setOnAction((ActionEvent event)->{
   System.out.println(tf1.getText());
   String hoge = tf1.getText();
   l1.setText(hoge+"さん、こんにちは!");
  });
  //削除ボタン
  b2.setOnAction((ActionEvent event)->{
   tf1.setText("");
   l1.setText("");
  });
  Scene scene = new Scene(pane,350,350);//シーンのサイズ
  myStage.setTitle("Exe31");
  myStage.setScene(scene);
  myStage.show();
 }
}
 
 
PR

コメント

ブログ内検索

カレンダー

03 2025/04 05
S M T W T F S
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