0
javafx-8を使用してCheckBoxを作成しようとしていますが、CheckBox(String str)に関連付けられているラベルを初期化するコンストラクタは同様に定義されていませんsetSelectedメソッドとsetTextメソッドはライブラリに定義されていません。 最新バージョンのJava SE 8u131にアップデートしましたが、まだ問題があります。 は、ここでは、コードCheckBox(String str)コンストラクタが定義されていません
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;import javafx.stage.Stage;
public class CheckBox extends Application {
Stage window;
Scene scene;
Button button;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("JavaFX");
//Checkboxes
CheckBox box1 = new CheckBox("apples");
CheckBox box2 = new CheckBox("Tuna");
box2.setSelected(true);
//Button
button = new Button("Order Now!");
button.setOnAction(e -> handleOptions(box1, box2));
//Layout
VBox layout = new VBox(10);
layout.setPadding(new Insets(20, 20, 20, 20));
layout.getChildren().addAll(box1, box2, button);
scene = new Scene(layout, 300, 250);
window.setScene(scene);
window.show();
}
//Handle checkbox options
private void handleOptions(CheckBox box1, CheckBox box2){
String message = "Users order:\n";
if(box1.isSelected())
message += "Bacon\n";
if(box2.isSelected())
message += "Tuna\n";
System.out.println(message);
}
}
ここでエラーログ
CheckBox.java:24: error: constructor CheckBox in class CheckBox cannot be applied to given types;
CheckBox box1 = new CheckBox("apples");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
CheckBox.java:25: error: constructor CheckBox in class CheckBox cannot be applied to given types;
CheckBox box2 = new CheckBox("Tuna");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
CheckBox.java:26: error: cannot find symbol
box2.setSelected(true);
^
symbol: method setSelected(boolean)
location: variable box2 of type CheckBox
CheckBox.java:35: error: method addAll in interface ObservableList<E> cannot be applied to given types;
layout.getChildren().addAll(box1, box2, button);
^
required: Node[]
found: CheckBox,CheckBox,Button
reason: varargs mismatch; CheckBox cannot be converted to Node
where E is a type-variable:
E extends Object declared in interface ObservableList
CheckBox.java:46: error: cannot find symbol
if(box1.isSelected())
^
symbol: method isSelected()
location: variable box1 of type CheckBox
CheckBox.java:49: error: cannot find symbol
if(box2.isSelected())
^
symbol: method isSelected()
location: variable box2 of type CheckBox
にだ、私はUbuntuのシェルを介してそれをコンパイルしようとしているので、私はあまりにものEclipse IDEが、それのそのない問題を使用しています。 これを修正するにはどうすればよいですか? ありがとうございました!
独自のクラスは、あなたがこれを使う、という場合は、別の名前を使用して...トラブルのためのレシピです 'checkbox'で、呼ばれる、またはされます独自のクラス名を使用するには、javafx.scene.control.CheckBox checkbox = new javafx.scene.control.CheckBox( "..."); '完全修飾名を使用する必要があります。 – Itai