java.fxを使ってウィンドウの中に、ラベルを上下に貼り付けたいのですが、setTopとsetBottomがエラーを起こしてしまいます。
package kadai; import java.awt.Label; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class a1 extends Application{ private Label lb,at; private Button bt; public static void main(String[]args) { launch(args); } public void start (Stage stage)throws Exception{ lb = new Label("カートに追加しますか?"); at = new Label(""); Button bt = new Button("はい"); BorderPane bp = new BorderPane(); bp.setBottom(at); bp.setTop(lb); bp.setCenter(bt); Scene sc = new Scene(bp,300,200); sc.addEventHandler(MouseEvent.MOUSE_CLICKED,new a1EventHandler()); stage.setScene(sc); stage.setTitle("課題32"); stage.show(); } class a1EventHandler implements EventHandler<MouseEvent>{ public void handle(MouseEvent e) { at.setText("商品ページに戻ります。"); } } }
なお、エラーは次のようになります
Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.Error: Unresolved compilation problems: 型 BorderPane のメソッド setBottom(Node) は引数 (Label) に適用できません 型 BorderPane のメソッド setTop(Node) は引数 (Label) に適用できません at kadai.yasui.start(yasui.java:26) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177) ... 1 more Exception running application kadai.a1
どうすれば、ラベルを上下に貼り付けることができますでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/08 13:46