侧边栏壁纸
博主头像
老十三

敬年少热诚!

  • 累计撰写 30 篇文章
  • 累计创建 35 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

JavaFX小页面

老十三
2022-06-21 / 0 评论 / 2 点赞 / 123 阅读 / 1,330 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-06-21,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

JavaFX小页面

简易计算器

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

public class TwoPane extends Application {
    final static private int BUTTON_WIDTH = 40;
    final static private int BUTTON_HEIGHT = 40;
    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("简易计算器");
        Label label = new Label("");
        label.setAlignment(Pos.CENTER);
        label.setMinWidth(100);
        HBox expresssionPanel = new HBox(label);
        expresssionPanel.setAlignment(Pos.CENTER);
        GridPane keyboardPanel = new GridPane();
        for(int i = 1; i <= 9; ++i){
            Button btn = new Button(String.valueOf(i));
            btn.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
            btn.setOnAction(e -> label.setText(label.getText() + btn.getText()));
            keyboardPanel.add(btn, (i - 1) % 3, i > 3 ? (i > 6 ? 2 : 1) : 0);
        }
        Button zero = new Button(String.valueOf("0"));
        zero.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        zero.setOnAction(e -> label.setText(label.getText() + zero.getText()));
        Button plus = new Button(String.valueOf("+"));
        plus.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        plus.setOnAction(e -> label.setText(label.getText() + plus.getText()));
        Button minus = new Button(String.valueOf("-"));
        minus.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        minus.setOnAction(e -> label.setText(label.getText() + minus.getText()));
        Button time = new Button(String.valueOf("*"));
        time.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        time.setOnAction(e -> label.setText(label.getText() + time.getText()));
        Button divide = new Button(String.valueOf("/"));
        divide.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        divide.setOnAction(e -> label.setText(label.getText() + divide.getText()));
        Button calc = new Button(String.valueOf("="));
        calc.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        calc.setOnAction(e -> label.setText(label.getText() + calc.getText())/*TODO 计算逻辑代码待完成*/);
        keyboardPanel.add(zero, 0, 3);
        keyboardPanel.add(plus, 1, 3);
        keyboardPanel.add(minus, 2, 3);
        keyboardPanel.add(time, 0, 4);
        keyboardPanel.add(divide, 1, 4);
        keyboardPanel.add(calc, 2, 4);
        HBox root = new HBox(expresssionPanel, keyboardPanel);
        HBox.setHgrow(expresssionPanel, Priority.ALWAYS);
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }
}

密码验证界面

😩已经把javafx忘完了,赶作业写的和💩一样,各位见谅。

(如果你也是来抄作业的,那么我要告诉你,这个页面从上到下是由四个单行面板和一个网格面板构成的,最后放在一个列面板里显示的,而且按钮的下边框和有边框应该还有黑色的描边,宽度大概是0.5,我并没有实现,各位可以试试,实在是没有耐心了)

import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.geometry.Pos;
public class login extends Application
{
    final Label lab1=new Label("班组号: ");
    final Label lab2=new Label("密   "+"码: ");
    final Label lab3=new Label("请输入班组号和密码:");
    final Label lab4=new Label("兰州公寓乙班,总营业额:0.0元");
    final PasswordField pf=new PasswordField();
    final TextField tf=new TextField();
    final Button bt0=new Button("0");
    final Button bt1=new Button("1");
    final Button bt2=new Button("2");
    final Button bt3=new Button("3");
    final Button bt4=new Button("4");
    final Button bt5=new Button("5");
    final Button bt6=new Button("6");
    final Button bt7=new Button("7");
    final Button bt8=new Button("8");
    final Button bt9=new Button("9");
    final Button bt10=new Button("回删");
    final Button bt11=new Button("取消");
    final Button bt12=new Button("打印");
    final Button bt13=new Button("确认");
    @Override
    public void start(Stage primaryStage)
    {
        bt0.setPrefWidth(80);
        bt1.setPrefWidth(80);
        bt2.setPrefWidth(80);
        bt3.setPrefWidth(80);
        bt4.setPrefWidth(80);
        bt5.setPrefWidth(80);
        bt6.setPrefWidth(80);
        bt7.setPrefWidth(80);
        bt8.setPrefWidth(80);
        bt9.setPrefWidth(80);
        bt10.setPrefWidth(80);
        bt11.setPrefWidth(80);
        bt12.setPrefWidth(80);
        bt13.setPrefWidth(165);
        bt0.setStyle("-fx-font-weight:bold");
        bt1.setStyle("-fx-font-weight:bold");
        bt2.setStyle("-fx-font-weight:bold");
        bt3.setStyle("-fx-font-weight:bold");
        bt4.setStyle("-fx-font-weight:bold");
        bt5.setStyle("-fx-font-weight:bold");
        bt6.setStyle("-fx-font-weight:bold");
        bt7.setStyle("-fx-font-weight:bold");
        bt8.setStyle("-fx-font-weight:bold");
        bt9.setStyle("-fx-font-weight:bold");
        bt10.setStyle("-fx-font-weight:bold");
        bt11.setStyle("-fx-font-weight:bold");
        bt12.setStyle("-fx-font-weight:bold");
        bt13.setStyle("-fx-font-weight:bold");
        lab3.setStyle("-fx-font-weight:bold");
        lab4.setStyle("-fx-font-weight:bold");
        GridPane.setHalignment(bt13, HPos.RIGHT);
        HBox onePanel = new HBox(lab4);
        onePanel.setMargin(lab4,new Insets(5,5,5,5));
        lab3.setAlignment(Pos.CENTER);
        lab3.setMinWidth(100);
        HBox topPanel = new HBox(lab3);
        topPanel.setAlignment(Pos.CENTER);
        topPanel.setMargin(lab3,new Insets(20,10,10,10));
        BorderStroke borderStroke1 = new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, new CornerRadii(0), new BorderWidths(1, 0, 0, 0));
        Border border2 = new Border(borderStroke1);
        topPanel.setBorder(border2);
        tf.setPromptText("输入班组号");
        lab1.setAlignment(Pos.CENTER);
        tf.setAlignment(Pos.CENTER);
        HBox twoPanel = new HBox(lab1,tf);
        twoPanel.setAlignment(Pos.CENTER);
        twoPanel.setMargin(tf,new Insets(5));
        pf.setPromptText("输入密码");
        lab2.setAlignment(Pos.CENTER);
        lab2.setContentDisplay(ContentDisplay.RIGHT);
        pf.setAlignment(Pos.CENTER);
        HBox threePanel = new HBox(lab2,pf);
        threePanel.setAlignment(Pos.CENTER);
        threePanel.setMargin(pf,new Insets(5));
        GridPane rootGP=new GridPane();
        rootGP.setPadding(new Insets(10,8,10,8));
        rootGP.setHgap(5);
        rootGP.setVgap(5);
        rootGP.add(bt7,1,1);
        rootGP.add(bt8,2,1);
        rootGP.add(bt9,3,1);
        rootGP.add(bt4,1,2);
        rootGP.add(bt5,2,2);
        rootGP.add(bt6,3,2);
        rootGP.add(bt1,1,3);
        rootGP.add(bt2,2,3);
        rootGP.add(bt3,3,3);
        rootGP.add(bt10,1,4);
        rootGP.add(bt0,2,4);
        rootGP.add(bt11,3,4);
        rootGP.add(bt12,1,5);
        rootGP.add(bt13,2,5,2,1);
        GridPane.setHalignment(bt13, HPos.LEFT);
        BackgroundFill backgroundFill = new BackgroundFill(Paint.valueOf("#8a90a6"), new CornerRadii(0), new Insets(2,0,0,2));
        Background background = new Background(backgroundFill);
        bt0.setBackground(background);
        bt1.setBackground(background);
        bt2.setBackground(background);
        bt3.setBackground(background);
        bt4.setBackground(background);
        bt5.setBackground(background);
        bt6.setBackground(background);
        bt7.setBackground(background);
        bt8.setBackground(background);
        bt9.setBackground(background);
        bt10.setBackground(background);
        bt11.setBackground(background);
        bt12.setBackground(background);
        bt13.setBackground(background);
        bt1.setTextFill(Paint.valueOf("#19120a"));
        BorderStroke borderStroke = new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, new CornerRadii(0), new BorderWidths(1, 0, 0, 2));
        Border border = new Border(borderStroke);
        bt0.setBorder(border);
        bt1.setBorder(border);
        bt2.setBorder(border);
        bt3.setBorder(border);
        bt4.setBorder(border);
        bt5.setBorder(border);
        bt6.setBorder(border);
        bt7.setBorder(border);
        bt8.setBorder(border);
        bt9.setBorder(border);
        bt10.setBorder(border);
        bt11.setBorder(border);
        bt12.setBorder(border);
        bt13.setBorder(border);
        VBox root = new VBox(onePanel,topPanel,twoPanel,threePanel,rootGP);
        root.setStyle("-fx-background-color:#aeb9d9");
        Scene scene=new Scene(root,280,300);
        primaryStage.setTitle("密码验证");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

2

评论区