Show three cards | Java

简介: The Code from Java book (11th Edition) on page 498 Question 14.1_03

The Code from Java book (11th Edition) on page 498 Question 14.1_03

Before compiling the program please move image pack to the same peace as java code
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.image.*;
import javafx.geometry.Insets;

public class ShowThreeCards extends Application {
    @Override
    public void start(Stage primaryStage) {
        int c1=(int)((Math.random()*100)%54);
        int c2=(int)((Math.random()*100)%54);
        int c3=(int)((Math.random()*100)%54);
        Pane pane=new HBox();
        pane.setPadding(new Insets(5,5,5,5));
        String card1=new String("image/card/"+String.valueOf(c1)+".png");
        String card2=new String("image/card/"+String.valueOf(c2)+".png");
        String card3=new String("image/card/"+String.valueOf(c3)+".png");
        pane.getChildren().add(new ImageView(card1));
        pane.getChildren().add(new ImageView(card2));
        pane.getChildren().add(new ImageView(card3));

        Scene scene=new Scene(pane);
        primaryStage.setTitle("ThreeCards");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}
如有侵权,请联系作者删除
目录
相关文章
|
1月前
|
Java Linux Windows
Java“Could Not Create Java Virtual Machine”解决
当在Java中遇到“Could Not Create Java Virtual Machine”错误时,通常是由于内存设置不当、Java版本不兼容、类路径错误或操作系统限制等原因导致JVM无法启动。解决方法包括调整内存参数、确认Java版本兼容性、检查类路径和启动参数、以及检查用户权限和文件系统。
116 1
|
5月前
|
Java
java lab 8------7-1 sdut-JAVA-a contacts list(s)(multi-arraylists)
java lab 8------7-1 sdut-JAVA-a contacts list(s)(multi-arraylists)
22 0
|
5月前
|
Java
java lab8--------7-2 sdut-JAVA-Insert Integer element into array lists
java lab8--------7-2 sdut-JAVA-Insert Integer element into array lists
29 0
|
Java
Test Generic Matrix | Java
The Code from Java book (11th Edition) on page 17 Example 19.13
56 0
|
前端开发 Java Windows
java导出excel:Could not initialize class sun.awt.X11GraphicsEnvironment
java导出excel:Could not initialize class sun.awt.X11GraphicsEnvironment
352 0
java导出excel:Could not initialize class sun.awt.X11GraphicsEnvironment
|
Oracle Java 关系型数据库
JDK/JAVA Exception NSWindow drag regions should only be invalidated on the Main Thread
JDK/JAVA Exception NSWindow drag regions should only be invalidated on the Main Thread
153 0
|
安全 算法 Java
Inside Java Newscast #1 解读(下)
Inside Java Newscast #1 解读(下)
Inside Java Newscast #1 解读(下)
|
安全 前端开发 Java
Inside Java Newscast #1 解读(上)
Inside Java Newscast #1 解读(上)
Inside Java Newscast #1 解读(上)
|
网络协议 算法 Java
Inside Java Newscast #1 解读(中)
Inside Java Newscast #1 解读(中)
Inside Java Newscast #1 解读(中)