Animation 使用Xlint重新编译:未选中以获取详细信息

Animation 使用Xlint重新编译:未选中以获取详细信息,animation,canvas,javafx,event-handling,Animation,Canvas,Javafx,Event Handling,我制作了一个程序,在画布中创建一个矩形,并通过使用键盘箭头键的事件处理程序进行移动。还有一个带有选项1-5的选择框,用于表示所选的速度。速度为1表示矩形每按一次键移动1个像素,速度为2表示矩形每按一次键移动2个像素,依此类推。我的代码在netbeans中正确编译和运行,但是当我尝试在PuTTY中编译它时,我无法找出我做错了什么 我第一次收到的错误是 Note: AnimatedRectangle.java uses unchecked or unsafe operations.

我制作了一个程序,在画布中创建一个矩形,并通过使用键盘箭头键的事件处理程序进行移动。还有一个带有选项1-5的选择框,用于表示所选的速度。速度为1表示矩形每按一次键移动1个像素,速度为2表示矩形每按一次键移动2个像素,依此类推。我的代码在netbeans中正确编译和运行,但是当我尝试在PuTTY中编译它时,我无法找出我做错了什么

我第一次收到的错误是

Note: AnimatedRectangle.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 注意:AnimatedRectangle.java使用未经检查或不安全的操作。 注意:使用-Xlint重新编译:未选中以获取详细信息。 因此,我使用-Xlint重新编译,并得到以下输出:

AnimatedRectangle.java:71: warning: [unchecked] unchecked call to ChoiceBox(ObservableList<T>) as a member of the raw type ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList ( where T is a type variable: T extends Object declared in class ChoiceBox AnimatedRectangle.java:75: warning [unchecked] unchecked call to setValue(T) as a member of the raw type ChoiceBox cb.setValue("1"); where T is a type variable: T extends Object declared in class ChoiceBox 2 warnings AnimatedRectangle.java:71:警告:[未选中]未选中调用 ChoiceBox(ObservableList)作为原始类型ChoiceBox的成员 cb=新的选择框(FXCollections.observableArrayList( 其中T是一个类型变量: T扩展类ChoiceBox中声明的对象 java:75:警告[未选中]未选中调用 setValue(T)作为原始类型选择框的成员 cb.设定值(“1”); 其中T是一个类型变量: T扩展类ChoiceBox中声明的对象 2警告 这是我的全部代码:

import javafx.application.Application;
import javafx.collections.FXCollections; 
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.ChoiceBox;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.stage.Stage;


public class AnimatedRectangle extends Application {

Group root;
Canvas canvas;
Scene scene;
GraphicsContext gc;
ChoiceBox cb;
String cbInput;
int speed;
int x, y, width, height;
int n = x + 1;
String userInput;



@Override
public void start(Stage primaryStage) {

    //declare rectangle variables
    width = 100;
    height = 50;
    y = 150;
    x = 150;
    n = x + 1;

    //declare a new group and a new canvas
    root = new Group();
    canvas = new Canvas(400, 400);

    //set the scene and make the background color white
    scene = new Scene(root, 400, 400, Color.WHITE);

    //create a 2D graphics context
    gc = canvas.getGraphicsContext2D();

    //create a green rectangle
    gc.setFill(Color.GREEN);
    gc.fillRect(150, 150, 100, 50);

    //create a choice box with options 1, 2, 3, 4, and 5
    cb = new ChoiceBox(FXCollections.observableArrayList(
    "1","2","3","4","5"));

    //set the pre-determined value to 1
    cb.setValue("1");

    //add the canvas and the choice box to the group
    root.getChildren().add(canvas);
    root.getChildren().add(cb);

    //add an event handler to the group. 
    //This event handler will first decide which choice box
    //is selected, and according to that, a series of events will occur.
    //The rectangle will either move right or left depending on
    //which key is pressed. The choice box options determine the
    //speed in which the rectangle will move. 1 meaning 1 pixel per move,
    //and 5 meaning 5 pixels per move, and so on.
    root.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
        @Override
        public void handle(KeyEvent event){

            userInput = cb.getValue().toString();

            if (userInput == "1"){
                switch (event.getCode()){
                    case RIGHT: //gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n+1, y, width, height);
                                x = n + 1;
                                n++;
                                break;

                    case LEFT:  gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n-1, y, width, height);
                                x = n - 1;
                                n--;  
                                break;
                }
            }

            if (userInput == "2"){
                switch (event.getCode()){
                    case RIGHT: gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n+2, y, width, height);
                                x = n + 2;
                                n = n + 2;
                                break;

                    case LEFT:  gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n-2, y, width, height);
                                x = n - 2;
                                n = n - 2;
                                break;
                }
            }
            if (userInput == "3"){
                switch (event.getCode()){
                    case RIGHT: gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n+3, y, width, height);
                                x = n + 3;
                                n = n + 3;
                                break;

                    case LEFT:  gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n-3, y, width, height);
                                x = n - 3;
                                n = n - 3; 
                                break;
                }
            }
            if (userInput == "4"){
                switch (event.getCode()){
                    case RIGHT: gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n+4, y, width, height);
                                x = n + 4;
                                n = n + 4;
                                break;

                    case LEFT:  gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n-4, y, width, height);
                                x = n - 4;
                                n = n - 4;  
                                break;
                }
            }
            if (userInput == "5"){
                switch (event.getCode()){
                    case RIGHT: gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n+5, y, width, height);
                                x = n + 5;
                                n = n + 5;
                                break;

                    case LEFT:  gc.fillRect(x, y, width, height);
                                gc.clearRect(x, y, width, height);
                                gc.fillRect(n-5, y, width, height);
                                x = n - 5;
                                n = n -5;  
                                break;
                }
            }
        }
    });

    //set the title & scene of the stage
    primaryStage.setTitle("Move rectangle");
    primaryStage.setScene(scene);
    primaryStage.show();


}

//the main class
public static void main(String[] args) {
    launch(args);
}

}
导入javafx.application.application;
导入javafx.collections.FXCollections;
导入javafx.event.EventHandler;
导入javafx.scene.Group;
导入javafx.scene.scene;
导入javafx.scene.canvas.canvas;
导入javafx.scene.canvas.GraphicsContext;
导入javafx.scene.control.ChoiceBox;
导入javafx.scene.input.KeyEvent;
导入javafx.scene.paint.Color;
导入javafx.stage.stage;
公共类AnimatedRectangle扩展应用程序{
群根;
帆布;
场景;
GraphicsContext gc;
选择框cb;
字符串输入;
整数速度;
整数x,y,宽度,高度;
int n=x+1;
字符串用户输入;
@凌驾
公共无效开始(阶段primaryStage){
//声明矩形变量
宽度=100;
高度=50;
y=150;
x=150;
n=x+1;
//声明一个新组和一个新画布
root=新组();
画布=新画布(400400);
//设置场景并使背景色为白色
场景=新场景(根,400,400,颜色.白色);
//创建二维图形上下文
gc=canvas.getGraphicsContext2D();
//创建一个绿色矩形
gc.setFill(颜色为绿色);
gc.fillRect(15015010050);
//创建包含选项1、2、3、4和5的选项框
cb=新的选择框(FXCollections.observableArrayList(
"1","2","3","4","5"));
//将预先确定的值设置为1
cb.设定值(“1”);
//将画布和选择框添加到组中
root.getChildren().add(画布);
root.getChildren().add(cb);
//向组中添加事件处理程序。
//此事件处理程序将首先决定哪个选项框
//选择,并根据该选项,将发生一系列事件。
//矩形将根据具体情况向右或向左移动
//按下哪个键。选择框选项决定
//矩形移动的速度。1表示每移动一个像素,
//5表示每移动5个像素,依此类推。
root.addEventHandler(按下KeyEvent.KEY_,新建EventHandler()){
@凌驾
公共无效句柄(KeyEvent事件){
userInput=cb.getValue().toString();
如果(用户输入=“1”){
开关(event.getCode()){
右键://gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n+1,y,宽度,高度);
x=n+1;
n++;
打破
左格:gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n-1,y,宽度,高度);
x=n-1;
n--;
打破
}
}
如果(用户输入=“2”){
开关(event.getCode()){
大小写右侧:gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n+2,y,宽度,高度);
x=n+2;
n=n+2;
打破
左格:gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n-2,y,宽度,高度);
x=n-2;
n=n-2;
打破
}
}
如果(用户输入=“3”){
开关(event.getCode()){
大小写右侧:gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n+3,y,宽度,高度);
x=n+3;
n=n+3;
打破
左格:gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n-3,y,宽度,高度);
x=n-3;
n=n-3;
打破
}
}
如果(用户输入=“4”){
开关(event.getCode()){
大小写右侧:gc.fillRect(x,y,宽度,高度);
gc.clearRect(x,y,宽度,高度);
gc.fillRect(n+4,y,w