修改界面,特别注意传参数,要赋值写,构造方法

public class UpdateStaff extends Application {

 

 // 网格布局

 GridPane gp = new GridPane();

 String path = null;// 扩大作用域 为了方便拿值

 

  private HTIndex i=null;

  private staff sf=null;

 //

 // //构造方法

  public UpdateStaff (HTIndex i,staff sf) {

   this.i=i;

   this.sf=sf;

   //给各个控件赋值

   tfb.setText(this.sf.getSname());

   tfc.setText(this.sf.getSpassword());

   tfh.setText(this.sf.getSpassword());

   tfh.setText(this.sf.getSpassword());

   if("男".equals(this.sf.getSsex())) {//如果当前学生的性别为男

    rba.setSelected(true);//就让男选中

   }

   else {

    rbb.setSelected(true);

   }

   tff.setText(this.sf.getSmoney()+"");

   

   ba.setGraphic(new ImageView(new Image(sf.getStplj(), 100, 100, true, true)));

  

   

 

  }

 // 按钮们

 Button ba = new Button("", new ImageView(new Image("images/image.png", 100, 100, true, true)));

 Button bb = new Button("确定", new ImageView(new Image("images/确定.png")));

 Button bc = new Button("取消", new ImageView(new Image("images/取消.png")));

 Button bd = new Button("清空", new ImageView(new Image("images/清空.png")));

 TextField tfb = new TextField();

 PasswordField tfc = new PasswordField();

 PasswordField tfh = new PasswordField();

 TextField tff = new TextField();

 DatePicker dp = new DatePicker(LocalDate.of(2022,11,1));

 // 单选框

   RadioButton rba = new RadioButton("男♂");

   RadioButton rbb = new RadioButton("女♀");

   

   Label le = new Label("员工头像图片路径:", new ImageView(new Image("images/path.png")));

 

  {

  

  // 代码块 用来定义控件、增加控件

  gp.setAlignment(Pos.CENTER);

  gp.setHgap(50);

  gp.setVgap(20);

  // 上

  GridPane top = new GridPane();

  Label ls = new Label("修改员工");

  gp.addRow(0, ls);

  ls.setFont(Font.font("STXINWEI", 40));

  ls.setTextFill(Color.RED);

  top.setAlignment(Pos.CENTER);

 

  //

  // 员工姓名

  Label lb = new Label("员工姓名:");

  

  gp.addRow(1, lb, tfb);

 

  // 员工密码

 

  Label lc = new Label("账号密码:", new ImageView(new Image("images/type.png")));

  gp.addRow(2, lc, tfc);

  Label("确认密码:", new ImageView(new Image("images/type.png")));

  

  gp.addRow(3, lh, tfh);

 

  // 员工性别

  Label ld = new Label("员工性别:");

 

  

  // 单选功能

  ToggleGroup tg = new ToggleGroup();

  // 水平布局

  HBox h1 = new HBox(rba, rbb);// 看做是一个整体

 

  // 设置单选功能

  rba.setToggleGroup(tg);

  rbb.setToggleGroup(tg);

  // 让男默认选中

  rba.setSelected(true);

 

  gp.addRow(4, ld, h1);

 

  // 员工头像图片路径

  

  gp.addRow(5, le, ba);

 

  // 员工工资

  Label lf = new Label("员工工资:");

  

  gp.addRow(6, lf, tff);

 

  // 员工入职日期

  Label lg = new Label("员工入职日期", new ImageView(new Image("images/time.png")));

  // 日期选择器

  gp.addRow(7, lg, dp);

 

  BackgroundSize size = new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true);

  Background b = new Background(new BackgroundImage(new Image("images/背景.jpg"), BackgroundRepeat.NO_REPEAT,

    BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, size));

  gp.setBackground(b);

 

  // 按钮

  gp.addRow(8, bb, bc, bd);

 

    // 清空点击事件

  bd.setOnAction(e -> {

   // 清空框

   tfb.setText("");

   tfc.setText("");

   rba.setSelected(false);

   rbb.setSelected(false);

   tff.setText("");

   // tfg.setText("");

 

  });

 

  //

}

   

  

 @Override

 public void start(Stage stage) throws Exception {

  

  // 确定按钮的点击事件

    bb.setOnAction(e -> {

     // //拿所有的值

     // //1.员工姓名

     String sname = tfb.getText();

     //

     // //员工密码

     String spassword1 = tfc.getText();

     String spassword2 = tfh.getText();

     

     // //员工性别

     String ssex = rba.isSelected() ? "男" : "女";// 性别

     // //员工工资

     String a = tff.getText();

     double smoney = 0;

     if (a.length() != 0) {

      smoney = Double.parseDouble(a);

     }

 

     // 6.员工入职日期

 

     LocalDate d = dp.getValue();

     // 转为String

     String srzrq = d.toString();

     

     // 不能为空

     if (sname.length() != 0) {

      if (spassword1.length() != 0) {

       if (ssex.length() != 0) {

        if (smoney != 0) {

 if (path.length() != 0) {

          if (srzrq.length() != 0) {

           if (spassword1.equals(spassword2)) {

            // 调用注册的方法

            StaffDao sd = new StaffDao();

            // 实例化一个员工

            staff sF = new staff(sname, spassword1, ssex, smoney, path, srzrq);

            int n = sd.Updates(sF, this.sf.getSid());

            if (n > 0) {

             new Alert(AlertType.INFORMATION, "修改成功!").showAndWait();

             stage.close();

             this.i.staffShow();

            } else {

             new Alert(AlertType.ERROR, "修改失败").showAndWait();

            }

           } else {

            new Alert(AlertType.ERROR, "两次密码不一致").showAndWait();

           }

 

          } else {

           new Alert(AlertType.ERROR, "您的员工入职日期不能为空").showAndWait();

 

          }

// } else {

// new Alert(AlertType.ERROR, "您的工头像图片路径不能为空").showAndWait();

  //

// }

        } else {

         new Alert(AlertType.ERROR, "您的员工工资不能为空").showAndWait();

 

        }

       } else {

        new Alert(AlertType.ERROR, "您的姓别不能为空").showAndWait();

 

       }

 

      } else {

       new Alert(AlertType.ERROR, "您的员工密码不能为空").showAndWait();

 

      }

     } else {

      new Alert(AlertType.ERROR, "您的姓名不能为空").showAndWait();

 

     }

 

     

    });

 

  //

  // 取消点击事件

  bc.setOnAction(e -> {

   Alert a = new Alert(AlertType.CONFIRMATION, "确定要关闭?");

   Optional<ButtonType> oo = a.showAndWait();

   if (oo.get() == ButtonType.OK) {// 用户选择了'确定'

    // 把自己关闭

    stage.close();

 

   }

 

  });

  // 图片文件按钮 点击事件

  ba.setOnAction(e -> {

   // 点击图片 弹出文件选择器

   FileChooser fc = new FileChooser();

   // 定义文件后缀名过滤器

   FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("image",

     new String[] { "*.jpg", "*.png" });

   // 为文件选择器添加下拉框

   fc.getExtensionFilters().add(filter);

   // 设置初始文件夹

   fc.setInitialDirectory(new File("C:\\Users\\爷爷\\Desktop\\images"));

   // 显示并且打开对话框 在当前舞台上

   File file = fc.showOpenDialog(stage);

   // 判空

  if (file != null) {

 

    // 拿到其绝对路径

    path = "file:" + file.getAbsolutePath();

 

    // 给按钮重新设置图片 实现图片的预览效果

    ba.setGraphic(new ImageView(new Image(path, 100, 100, true, true)));

   }

  });

 

  stage.getIcons().add(new Image("images/网站引流.png", 100, 100, true, true));

  stage.setResizable(false);

  stage.setScene(new Scene(gp, 700, 700));

  stage.setTitle("修改员工");

  stage.show();

 }

 

 public static void main(String[] args) {

  Application.launch(args);

 }

 

}f87072eaaa34476fa7db8bbbfe53c857.png

 

a21000702970419abb1429a587aceca9.png

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

桃花坞生动的芒果

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值