文章目录
1.实现如图的登录窗口界面
实现代码如下:
package com.boyi.itLianXi.javagui;
/**
*
* @program 实现登录窗口界面
* @since 1.0
* @author 博弈
*/
import javax.swing.*;
import java.awt.*;
public class Login extends JFrame {
public void createFrame(){
this.setSize(400,180);
this.setTitle("欢迎登陆");
this.setLocationRelativeTo(null);//水平位置居中
this.setResizable(false);//不能改变大小
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口退出
JPanel jp=new JPanel(new GridLayout(3,1));
JPanel accountjp=new JPanel();
JLabel acountLable=new JLabel("管理员");
JTextField accountText=new JTextField(15);
accountjp.add(acountLable);
accountjp.add(accountText);
JPanel passwordjp=new JPanel();
JLabel passwordLable=new JLabel("密码");
JPasswordField passwordField=new JPasswordField(15);//密码框
passwordjp.add(passwordLable);
passwordjp.add(passwordField);
JPanel btnjp=new JPanel();
JButton jButton1=new JButton("登录");
JButton jButton2=new JButton("取消");
btnjp.add(jButton1);
btnjp.add(jButton2);
jp.add(accountjp);
jp.add(passwordjp);
jp.add(btnjp);
this.add(jp);
this.setVisible(true);
}
}
package com.boyi.itLianXi.javagui;
public class RunLogin {
public static void main(String[] args) {
new Login().createFrame();
}
}
运行结果如图: