import javax.swing.*;
import java.awt.*;public class Registe extends JFrame {
GridBagLayout grid1;
JPanel jpRegiste; JLabel lblUserName;
JTextField txtUserName; JLabel lblUserPasswd;
JPasswordField txtUserPasswd; JButton btnLogin;
JButton btnRegiste; GridBagConstraints gbc; public Registe() {
//super(title);
jpRegiste = (JPanel) getContentPane();
grid1 = new GridBagLayout();
gbc = new GridBagConstraints();
jpRegiste.setLayout(grid1);
; lblUserName = new JLabel("用户名:");
txtUserName = new JTextField(20);
lblUserPasswd = new JLabel("密 码:");
txtUserPasswd = new JPasswordField(20); btnLogin = new JButton("登录");
btnRegiste = new JButton("注册"); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
grid1.setConstraints(lblUserName, gbc);
jpRegiste.add(lblUserName); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 5;
grid1.setConstraints(txtUserName, gbc);
jpRegiste.add(txtUserName); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 9;
grid1.setConstraints(lblUserPasswd, gbc);
jpRegiste.add(lblUserPasswd); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 9;
grid1.setConstraints(txtUserPasswd, gbc);
jpRegiste.add(txtUserPasswd); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 3;
gbc.gridy = 17;
grid1.setConstraints(btnLogin, gbc);
jpRegiste.add(btnLogin); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 7;
gbc.gridy = 17;
grid1.setConstraints(btnRegiste, gbc);
jpRegiste.add(btnRegiste);
} public static void main(String[] args) {
Registe registe = new Registe();
registe.setSize(300, 200);
registe.setVisible(true); }
}
主要是你的构造函数前面加了void,这是错误的。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货