zoukankan      html  css  js  c++  java
  • JavaFX移动小球

    package javaseniorprograme;
    
    import javafx.application.Application;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.stage.Stage;
    
    /**
     * 移动小球
     * @author 李安国
     */
    public class Exercise15_03 extends Application{
        @Override
        public void start(Stage primaryStage){
            // 创建一个面板
            Pane pane = new Pane();
            // 创建一个HBox
            HBox hbox = new HBox();
            // 创建四个按钮
            Button bt1 = new Button("Left");
            Button bt2 = new Button("Right");
            Button bt3 = new Button("Up");
            Button bt4 = new Button("Down");
            hbox.setAlignment(Pos.CENTER); 
            hbox.setSpacing(10);
            hbox.getChildren().addAll(bt1,bt2,bt3,bt4);
            // 创建一个圆
            Circle circle = new Circle(50,50,25);
            // 设置轮廓颜色
            circle.setStroke(Color.BLACK); 
            // 设置填充色
            circle.setFill(Color.WHITE); 
            pane.getChildren().add(circle);
          
            // 创建一个BorderPane面板
            BorderPane bdpane = new BorderPane();
            bdpane.setCenter(pane);
            bdpane.setBottom(hbox);
            Scene scene = new Scene(bdpane,300,300);
              
            bt1.setOnAction(e->{circle.setCenterX(circle.getCenterX() > 0 ? circle.getCenterX() - 10 : scene.getWidth());});
            bt2.setOnAction(e->{circle.setCenterX(circle.getCenterX() < scene.getWidth()? circle.getCenterX() + 10 : 0);});
            bt3.setOnAction(e->{circle.setCenterY(circle.getCenterY() > 0 ? circle.getCenterY() - 10 : scene.getHeight());});
            bt4.setOnAction(e->{circle.setCenterY(circle.getCenterY() < scene.getHeight()? circle.getCenterY() + 10 : 0);});
            primaryStage.setTitle("Exercise15_03");
            primaryStage.setScene(scene);
            primaryStage.show();
            
        }
        public static void main(String[] args){
            launch(args);
        }

    }

    爱我没结果!
  • 相关阅读:
    从Oracle提供两种cube产品说开
    Sql Server DWBI的几个学习资料
    Unload Oracle data into text file
    初学Java的几个tips
    我常用的Oracle知识点汇总
    benefits by using svn
    如何在windows上使用putty来显示远端linux的桌面
    building commercial website using Microsoft tech stack
    Understand Thread and Lock
    Update google calendar by sunbird
  • 原文地址:https://www.cnblogs.com/angoli/p/12685066.html
Copyright © 2011-2022 走看看