JavaFx-微波炉界面演示

版权声明:就是码字也不容易啊 https://blog.csdn.net/qq_40946921/article/details/84496552

请采用JavaFX平台实现如下微波炉界面,在此基础上采用事件驱动编程实现按钮start和stop的功能:当点击按钮start,文本框中的内容就会显示“正在加热中……”,并显示相应的图片;当点击按钮stop,文本框中的内容就会显示“微波炉已停止加热”,并切换图片。

提示:改变文本框中的内容可用TextField的setText(String s)方法;改变左侧上Label上的图

片可用其setGraphic(ImageView imgView)方法。

 

 

    没有点击start和stop效果                                     点击start效果                                          再点击stop效果

运行截图

 

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Microwava extends Application {
    Image food[]={new Image("food1.jpg"),new Image("food2.jpg")};
    ImageView foodView=new ImageView(food[1]);
    TextField state=new TextField("微波炉已停止加热......");
    Button bt;
    public void start(Stage stage){
        GridPane root=new GridPane();
        root.setGridLinesVisible(true);
        root.add(foodView,0,0,1,5);
        root.add(state,1,0,3,1);
        for(int i=0;i<3;i++){
            for(int j=1;j<=3;j++){
                bt=new Button(String.valueOf(i*3+j));
                bt.setMinSize(50,35);
                bt.setLayoutY(100);
                root.add(bt,j,i+1);
            }
        }
        bt=new Button("0");
        bt.setMinSize(50,35);
        root.add(bt,1,4);
        Button start=new Button("start");
        start.setMinSize(50,35);
        root.add(start,2,4);
        start.setOnMouseClicked(e->{
            foodView.setImage(food[0]);
            state.setText("正在加热中......");
        });
        Button stop=new Button("stop");
        stop.setMinSize(50,35);
        root.add(stop,3,4);
        stop.setOnMouseClicked(e->{
            foodView.setImage(food[1]);
            state.setText("微波炉已停止加热......");
        });
        Scene scene=new Scene(root,340,155);
        state.setEditable(false);
        stage.setResizable(false);
        stage.setScene(scene);
        stage.setTitle("微波炉");
        stage.show();
    }
}

素材 :https://pan.baidu.com/s/1_gWn0YZlSsMVNaPimzaLrQ

猜你喜欢

转载自blog.csdn.net/qq_40946921/article/details/84496552
今日推荐