编写一个程序来模拟交通信号灯。程序可以让用户从红、黄、绿三种颜色灯中选择一种。当选择一个按钮后,相应的灯被打开。程序开始时所有的灯都是不亮的。
代码如下:
package sample;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
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.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
BorderPane root =

该博客介绍了一个使用JavaFX编写的交通信号灯模拟程序,用户可以选择红、黄、绿三种颜色,点击后相应灯光会在GUI界面上显示。程序启动时所有灯默认关闭。
296

被折叠的 条评论
为什么被折叠?



