Java+Swing+Mysql学生成绩管理系统(DAY 5)

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

**开源地址:https://docs.qq.com/doc/DSmxTbFJ1cmN1R2dB **

    resetBtn.setFont(centerFont);



    contentPane.setBackground(Color.pink);



    //把组件加入到面板上

    centerPanel.add(userNameLabel);

    centerPanel.add(userPwdLabel);

    centerPanel.add(nameTxd);

    centerPanel.add(pwdFiled);

    centerPanel.add(loginBtn);

    centerPanel.add(resetBtn);



    contentPane.add(titleNameLabel,BorderLayout.NORTH);

    contentPane.add(centerPanel,BorderLayout.CENTER);



    //获取组件的宽度Spring.width(组件名)用户名和用户名文本框组件

    Spring titleLabelWidth=Spring.width(userNameLabel);

    Spring titleTextWidth=Spring.width(nameTxd);

    Spring spaceWidth=Spring.constant(20);//userNameLabel和nameTxd的间距

    Spring totalWidth=Spring.sum(Spring.sum(titleLabelWidth,titleTextWidth),spaceWidth);

    int offSetX=totalWidth.getValue()/2;



     /*

    SpringLayout:布局管理器

    SpringLayout.Constraints:使用弹簧布局的容器里面的组件的布局约束,每个组件对应一个

    Spring:能够进行四则运算的整数

     */

    /*

    窗口相当于一个左顶角为原点的第四象限的坐标轴



     */

    //1.设置好用户名标签的位置(约束)

    SpringLayout.Constraints titleLabelCon=spLayout.getConstraints(userNameLabel);

    //用户名标签userNameLabel的西边参考centerPanel组件水平中心点方向左偏移offSetX的距离

    spLayout.putConstraint(SpringLayout.WEST,userNameLabel,-offSetX,SpringLayout.HORIZONTAL_CENTER,centerPanel);

    //设置用户名标签的垂直标签

    spLayout.putConstraint(SpringLayout.NORTH,userNameLabel,20,SpringLayout.NORTH,centerPanel);

    //or使用setY()设置垂直偏移量

    // titleLabelCon.setY(Spring.constant(50));//垂直偏移量



    //2.设置用户名文本框nameTxd的位置(约束)

    spLayout.putConstraint(SpringLayout.WEST,nameTxd,20,SpringLayout.EAST,userNameLabel);

    spLayout.putConstraint(SpringLayout.NORTH,nameTxd,0,SpringLayout.NORTH,userNameLabel);



    //3.设置密码标签userPwdLabel的位置

    spLayout.putConstraint(SpringLayout.NORTH,userPwdLabel,20,SpringLayout.SOUTH,userNameLabel);

    spLayout.putConstraint(SpringLayout.EAST,userPwdLabel,0,SpringLayout.EAST,userNameLabel);



    //4.设置密码文本框pwdFiled的位置(约束)

    spLayout.putConstraint(SpringLayout.WEST,pwdFiled,20,SpringLayout.EAST,userPwdLabel);

    spLayout.putConstraint(SpringLayout.NORTH,pwdFiled,0,SpringLayout.NORTH,userPwdLabel);



    //5.设置登录按钮loginBtn的位置

    spLayout.putConstraint(SpringLayout.EAST,loginBtn,-20,SpringLayout.HORIZONTAL_CENTER,centerPanel);

    spLayout.putConstraint(SpringLayout.NORTH,loginBtn,50,SpringLayout.SOUTH,pwdFiled);



    //6.设置重置按钮resetBtn的位置

    spLayout.putConstraint(SpringLayout.WEST,resetBtn,20,SpringLayout.HORIZONTAL_CENTER,centerPanel);

    spLayout.putConstraint(SpringLayout.NORTH,resetBtn,50,SpringLayout.SOUTH,pwdFiled);



    //设置窗口图片

    URL imgUrl=LoginViewTest.class.getClassLoader().getResource("LoginView.jpg");

    setIconImage(new ImageIcon(imgUrl).getImage());

    //设置窗口基本参数

    setSize(600,400);

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    setLocationRelativeTo(null);

    setResizable(false);

    setVisible(true);

}

public static void main(String[] args){

    new LoginViewTest();

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值