
请问这里哪里错了?我是照着书本来抄的。
packagefine;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;classGbl1exte...
package fine;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Gbl1 extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame jf;
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);
}
Gbl1(){
jf = new JFrame("信息管理系统");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gbl = new GridBagLayout();
setLayout(gbl);
jf.add(this,BorderLayout.WEST);
jf.setSize(300, 200);
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;
jf.setLocation(x, y);
JButton ok = new JButton("确认");
JButton cancel = new JButton("取消");
JLabel title = new JLabel("布局管理器测试窗口");
JLabel name = new JLabel("用户名");
JLabel password = new JLabel("密码");
final JTextField nameinput = new JTextField(15);
final JTextField passwordinput = new JTextField(15);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.EAST;
constraints.weightx = 3;
constraints.weighty = 4;
add(title,constraints,0,0,4,1);
add(name,constraints,0,1,1,1);
add(password,constraints,0,2,1,1);
add(nameinput,constraints,2,1,1,1);
add(passwordinput,constraints,2,2,1,1);
add(ok,constraints,0,3,1,1);
add(cancel,constraints,2,3,1,1);
jf.setResizable(false);
jf.setVisible(true);
}
}
public class Gbl1 { //这个Gbl1提示错误了:the type 类名 is already defined
public static void main(String[] args) {
login log = new login();
}
} 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Gbl1 extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame jf;
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);
}
Gbl1(){
jf = new JFrame("信息管理系统");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gbl = new GridBagLayout();
setLayout(gbl);
jf.add(this,BorderLayout.WEST);
jf.setSize(300, 200);
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;
jf.setLocation(x, y);
JButton ok = new JButton("确认");
JButton cancel = new JButton("取消");
JLabel title = new JLabel("布局管理器测试窗口");
JLabel name = new JLabel("用户名");
JLabel password = new JLabel("密码");
final JTextField nameinput = new JTextField(15);
final JTextField passwordinput = new JTextField(15);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.EAST;
constraints.weightx = 3;
constraints.weighty = 4;
add(title,constraints,0,0,4,1);
add(name,constraints,0,1,1,1);
add(password,constraints,0,2,1,1);
add(nameinput,constraints,2,1,1,1);
add(passwordinput,constraints,2,2,1,1);
add(ok,constraints,0,3,1,1);
add(cancel,constraints,2,3,1,1);
jf.setResizable(false);
jf.setVisible(true);
}
}
public class Gbl1 { //这个Gbl1提示错误了:the type 类名 is already defined
public static void main(String[] args) {
login log = new login();
}
} 展开
展开全部
public class Gbl1
class Gbl1
这个重复了
class Gbl1
这个重复了
更多追问追答
追问
如何修改?
追答
class Gbl1需要改成其他名字, public class Gbl1这个不能改, 因为这个文件的文件名必须和这个Gbl1一致
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询