import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class Login implements ActionListener{
JFrame f;
JPanel pnl;
JLabel lblinfo;
JLabel lblusername;
JLabel lbluserpwd;
JTextField txtusername;
JPasswordField txtuserpwd;
JButton btnEnter;
JButton btnCancel;
static int count=0;
public Login(){
     try{
     f.setDefaultLookAndFeelDecorated(true);     }catch(Exception e){
     e.printStackTrace();
     }
     f.setLocationRelativeTo(null);
f = new JFrame("管理员登陆");
pnl = new JPanel();
lblinfo = new JLabel("管理员登陆");
lblusername = new JLabel("用户名:");
lbluserpwd = new JLabel("密码:");
txtusername = new JTextField();
txtuserpwd = new JPasswordField();
btnEnter = new JButton(new ImageIcon(".\\login.gif"));
btnCancel = new JButton(new ImageIcon(".\\exit.gif"));
}
public void action(){
newobj();
f.setLayout(null);
f.setVisible(true);
f.setSize(300,220);
pnl.setLayout(null);
pnl.setVisible(true);
pnl.add(lblusername);
pnl.add(lblinfo);
pnl.add(lbluserpwd);
pnl.add(txtusername);
pnl.add(txtuserpwd);
pnl.add(btnCancel);
pnl.add(btnEnter);
btnEnter.addActionListener(this);
btnCancel.addActionListener(this);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
int num = JOptionPane.showConfirmDialog(f,"确定要退出吗?","提示",JOptionPane.OK_CANCEL_OPTION);
     if(num == JOptionPane.YES_OPTION){
     System.exit(0);
     }else{
     return;
     }
}
});
f.add(pnl);
}
public void newobj(){
pnl.setBounds(new Rectangle(6,3,280,180));
pnl.setBorder(BorderFactory.createEtchedBorder());
lblinfo.setBounds(new Rectangle(100,25,100,20));
lblinfo.setFont(new Font("宋体",Font.BOLD,15));
lblusername.setBounds(new Rectangle(50,55,60,15));
lbluserpwd.setBounds(new Rectangle(62,95,60,15));
txtusername.setBounds(new Rectangle(100,53,120,20));
txtuserpwd.setBounds(new Rectangle(100,93,120,20));
btnEnter.setBounds(new Rectangle(60,140,70,30));
btnCancel.setBounds(new Rectangle(165,140,70,30));
btnEnter.setBorder(null);
btnCancel.setBorder(null);
}
public static void main(String[] args) {
Login lg = new Login();
lg.action();
}
public void actionPerformed(ActionEvent a){

if(a.getSource()==btnEnter){
if(!((txtusername.getText().isEmpty())||(txtuserpwd.getPassword().toString().isEmpty()))){
Conn con = new Conn();
boolean flag = con.selectbase(this);
if(flag){
JOptionPane.showMessageDialog(f,"登陆成功");
}else{
count++;
if(count>=3){
JOptionPane.showMessageDialog(f,"你已经尝试三次密码错误,程序自动关闭");
System.exit(0);
}
JOptionPane.showMessageDialog(f,"用户名或密码错误");
}
con.close();
}else{
JOptionPane.showMessageDialog(f,"用户名或密码不能为空");
}
}else if(a.getSource()==btnCancel){
int num = JOptionPane.showConfirmDialog(f,"确定要退出吗?","提示",JOptionPane.OK_CANCEL_OPTION);
     if(num == JOptionPane.YES_OPTION){
     System.exit(0);
     }else{
     return;
     }
}
}
public String getAdminUser(){
String user = txtusername.getText().trim();
return user;
}
public String getAdminPwd(){
String pwd = new String(txtuserpwd.getPassword()).trim();
return pwd;
}
}这个能用WINDOWS装饰...但是不能居中,放上去,没效..呵呵.还有一个不能用WINDOWS装饰,但是可以居中的代码太长,所以不放上来了..这个解决了那个应该没问题..麻烦,高手指点一下,谢谢...