📄 login.java
字号:
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.*;
public class login extends JPanel
{
static final int WIDTH=300;
static final int HEIGHT=150;
public void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)
{
constraints.gridx=x;
constraints.gridy=y;
constraints.gridwidth=w;
constraints.gridheight=h;
add(c,constraints);
}
public static void main(String[] args)
{
JFrame loginframe=new JFrame("信息管理系统");
loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
login l=new login();
GridBagLayout lay=new GridBagLayout();
l.setLayout(lay);
loginframe.add(l, BorderLayout.WEST);
loginframe.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=screenSize.width;
int height=screenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
loginframe.setLocation(x,y);
JButton ok=new JButton("登陆");
JButton cancel=new JButton("放弃");
JLabel title=new JLabel("信 息 系 统 登 陆 窗 口");
JLabel name=new JLabel("用户名");
JLabel password=new JLabel("密 码");
JTextField nameinput=new JTextField(15);
JPasswordField passwordinput=new JPasswordField(15);
GridBagConstraints constraints=new GridBagConstraints();
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.EAST;
constraints.weightx=3;
constraints.weighty=4;
l.add(title,constraints,0,0,4,1);
l.add(name,constraints,0,1,1,1);
l.add(password,constraints,0,2,1,1);
l.add(nameinput,constraints,2,1,1,1);
l.add(passwordinput,constraints,2,2,1,1);
l.add(ok,constraints,0,3,1,1);
l.add(cancel,constraints,2,3,1,1);
loginframe.setResizable(false);
loginframe.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -