求助 高手帮忙!
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class login extends JPanel
{
static final int WIDTH=300;
static final int HEIGHT=150;
JFrame loginframe;
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);
}
login()
{
JFrame loginframe=new JFrame("性息管理系统");
loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout lay=new GridBagLayout();
setLayout(lay);
loginframe.add(this, 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 JLbel("用户名");
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.heighty=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);
loginframe.setResizable(false);
loginframe.setVisible(true);
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String nametext=nameinput.getText();
String passwordtext=passwoedinput.getText();
String str=new String(passwordtext);
boolean x=(nametext.equals("shy"));
boolean y=(str.equals("111"));
boolean z=(x&&y);
if(z==true)
{
loginframe.dispose();
//mainframe main=new mainframe();
System.out.pringln("正确");
}
else if(z==false)
{
nameinput.setText("");
passwordinput.setText("");
}
}
};
cancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
loginframe.dispose();
}
};
}
}
public class studentlog
{
public static void main(String[] args)
{
login log=new login();
}
}
一个登陆界面 编译不过!!!