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
에게있어 내가 우분투의 쉘을 통해 그것을 컴파일 시도 때문에 너무 이클립스하지만 그것없는 문제를 사용하고 있습니다. 어떻게 수정해야합니까? 미리 감사드립니다.
당신이로 이것을 사용하여 주장하는 경우 귀하 자신의 클래스가 다른 이름을 사용 ... 문제에 대한 조리법입니다'CheckBox', 전화, 또는 자신의 클래스 '이름을 사용하려면 javafx.scene.control.CheckBox checkbox = new javafx.scene.control.CheckBox ("...");'정규화 된 이름을 사용해야합니다. – Itai