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);
        }

    }

    爱我没结果!
  • 相关阅读:
    Python之struct模块浅谈
    看头发知健康
    ZeroMQ:云计算时代最好的通讯库
    粗盐热敷疗法经验汇总
    百度2011校招笔试算法题一
    new/delete 和malloc/free 的区别一般汇总
    Trie字典树
    百度2012校招笔试题之全排列与组合
    百度2011校招笔试算法题二
    执行程序的内存分布总结
  • 原文地址:https://www.cnblogs.com/angoli/p/12685066.html
Copyright © 2011-2022 走看看