2个回答
展开全部
你可以格式下,我想你大概要的这种效果,给你代码可以参考下:
import java.awt.*;
import javax.swing.*;
import java.awt.GridLayout;
@SuppressWarnings("serial")
public class LoginIFrame extends JFrame {
public static void main(String[] args) {
JFrame jf = new JFrame("注册");
JPanel jpanel = new JPanel();
jf.setContentPane(jpanel);
// 设置窗口在屏幕中居中显示
double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
int x = (int) (width - 300) / 2;
int y = (int) (height - 250) / 2;
jf.setBounds(x, y, 300, 150);
// 添加标签组件
GridLayout gird = new GridLayout(3, 0);
JPanel jpanel1 = new JPanel();
JPanel jpanel2 = new JPanel();
JPanel jpanel3 = new JPanel();
jpanel.setLayout(gird);
jpanel.add(jpanel1);
jpanel.add(jpanel2);
jpanel.add(jpanel3);
JLabel name = new JLabel("用 户 名:");
JTextField nametext = new JTextField(10);
JLabel pwd = new JLabel("密 码:");
JPasswordField pwd1 = new JPasswordField(10);
JLabel pwd2 = new JLabel("确认密码:");
JPasswordField pwd3 = new JPasswordField(10);
jpanel1.add(name);
jpanel1.add(nametext);
jpanel2.add(pwd);
jpanel2.add(pwd1);
jpanel3.add(pwd2);
jpanel3.add(pwd3);
jf.getLayeredPane().setLayout(null);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jpanel.setOpaque(false);
jpanel1.setOpaque(false);
jpanel2.setOpaque(false);
jpanel3.setOpaque(false);
jf.setVisible(true);
}
}
效果:
满意请采纳!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询