请帮忙看看这段代码有什么问题??(这是我在网上搜的)

/**
* LogIn.java
* Created on 08,07,2004
* @author mhl
* @version v0.1
*/
package com.jlu.mhl;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.MatteBorder;
import javax.swing.plaf.metal.MetalLookAndFeel;

public class LogIn extends JFrame
{
private JLabel UserJLabel,PassJLabel;
private JTextField UserNameJTField;
private JPasswordField PasswordJPField;
private JButton OkJButton,ExitJButton;
private JPanel UserNameJPanel,PasswordJPanel,ButtonJPanel;
private Action ExitAction,OkAction;
private Connection con;
private PreparedStatement sqlFind;
private ResultSet rs;
private String s_driver,s_url,s_User,s_Pass;
private static boolean JPBSS=true;
private ImageIcon icon_LogIn;
//init splash screen
private SplashScreen splashScreen;
private MdiMain newMdi;
private PropertiesRead newA;
private AllInformation conInfo;

public LogIn() {

super("LogIn...");

// init component.
InitialComponent();

// read attribute file
newA.Read();

// connect database
connect();

//display the splash screen
showJProgressBarSplashScreen();
showSplashScreen();

// WaitSplashScreen();

// set image for login frame.
icon_LogIn= new ImageIcon(getClass().getResource("./images/surfing.gif"));
setIconImage(icon_LogIn.getImage());
setResizable(false);

//Enter,Esc event
UserNameJTField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER) {
s_Pass=PasswordJPField.getText();
s_User=UserNameJTField.getText();
checkPopedom();
} else if (e.getKeyChar()==KeyEvent.VK_ESCAPE) {
int option=JOptionPane.showConfirmDialog(null,
" yes or no",
"Question", JOptionPane.YES_NO_OPTION);
// int option=MySetDialog.mySetDialog("e・ス・ス",20,"・スヌキ・ス・スヒウ・ス・ス・ス・?","マオヘウムッ・ス・ス");
if(option==0) {
System.exit(0);
}
}
}
});

//
PasswordJPField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
s_Pass=(String)PasswordJPField.getText();
s_User=UserNameJTField.getText();
checkPopedom();
//e.VK_ESCAPE==KeyEvent.VK_ESCAPE
} else if(e.getKeyChar()==KeyEvent.VK_ESCAPE) {
int option=JOptionPane.showConfirmDialog(null,
"yes or no",
"マオヘウQuestion", JOptionPane.YES_NO_OPTION);
if(option==0) {
System.exit(0);
}
}
}
});

// select all UserNameJTfield
UserNameJTField.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
UserNameJTField.selectAll();
}
});

// select all the PasswordJPField
PasswordJPField.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
PasswordJPField.select(0,20);
}
});

//
OkAction=new AbstractAction() {
public void actionPerformed(ActionEvent event) {
s_Pass=PasswordJPField.getText();
s_User=UserNameJTField.getText();
checkPopedom();
}
};
OkAction.putValue(Action.NAME,"Enter");
OkAction.putValue(Action.SMALL_ICON,
new ImageIcon(getClass().getResource("./images/ok.gif")));
OkAction.putValue(Action.SHORT_DESCRIPTION,"Enter");
OkAction.putValue(Action.MNEMONIC_KEY,new Integer('O'));
OkJButton=new JButton(OkAction);

//
OkJButton.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.VK_ENTER==KeyEvent.VK_ENTER) {
s_Pass=PasswordJPField.getText();
s_User=UserNameJTField.getText();
checkPopedom();
}
}
});

//
ExitAction=new AbstractAction() {
public void actionPerformed(ActionEvent event) {
int option=JOptionPane.showConfirmDialog(null,
"Are you sure to exit ?",
"Question", JOptionPane.YES_NO_OPTION);
if(option==0) {
System.exit(0);
}
}
};//end AbstracAction
ExitAction.putValue(Action.NAME,"Exit");
ExitAction.putValue(Action.SMALL_ICON,
new ImageIcon(getClass().getResource("./images/bb.gif")));
ExitAction.putValue(Action.SHORT_DESCRIPTION,"Exit");
ExitAction.putValue(Action.MNEMONIC_KEY,new Integer('E'));
ExitJButton=new JButton(ExitAction);

//
ExitJButton.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.VK_ESCAPE==KeyEvent.VK_ESCAPE) {
System.exit(1);
}
}
});

//
UserNameJPanel.add(UserJLabel);
UserNameJPanel.add(UserNameJTField);
PasswordJPanel.add(PassJLabel);
PasswordJPanel.add(PasswordJPField);
ButtonJPanel.add(OkJButton);
ButtonJPanel.add(ExitJButton);

//
Container c=getContentPane();
c.add(UserNameJPanel,BorderLayout.NORTH);
c.add(PasswordJPanel);
c.add(ButtonJPanel,BorderLayout.SOUTH);

setSize(240,130);
CenterOnScreen();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

}//End construct method

/**
* init login jlable,jtfiled,jpanel.
*/
public void InitialComponent() {
UserJLabel=new JLabel("UserName:");
PassJLabel=new JLabel("PassWord:");
UserNameJTField=new JTextField(10);
UserNameJTField.setText(System.getProperty("user.name"));
PasswordJPField=new JPasswordField(10);
UserNameJPanel=new JPanel();
PasswordJPanel=new JPanel();
ButtonJPanel=new JPanel();
newA=new PropertiesRead();
}

/**
* Connect database
*/
public void connect() {
try {
Class.forName(newA.s_Db_Driver);
//con=DriverManager.getConnection(newA.s_Db_Url);
con=DriverManager.getConnection(newA.s_Db_Url,newA.s_Db_LogName,newA.s_Db_LogPasswrd);
} catch (SQLException sqlE) {

JOptionPane.showMessageDialog(null,sqlE.getMessage()+"User or Pass Error",
"Info",JOptionPane.ERROR_MESSAGE);
showConInfo();
} catch (ClassNotFoundException cnfE) {
JOptionPane.showMessageDialog(null,cnfE.getMessage(),
"ClassNotFound",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}

/**
* select
*/
public void checkPopedom() {
try {
sqlFind=con.prepareStatement("select UserFName,UserLName from app_user "
+ "where UserFName = ? and UserLName = ? ");
sqlFind.setString(1,s_User);
sqlFind.setString(2,s_Pass);
rs=sqlFind.executeQuery();

if(!rs.next()) {
JOptionPane.showMessageDialog(null,
"no result !","Error",JOptionPane.ERROR_MESSAGE);
} else {
setVisible(false);

//init MDI frame
newMdi=new MdiMain();

sqlFind.close();
con.close();
dispose();
}
} catch (SQLException sqlE) {
JOptionPane.showMessageDialog(null,sqlE.getMessage(),
"Find Error",JOptionPane.ERROR_MESSAGE);
}
}

/**
* show JProgressBarSplashScreen
*/
public void showJProgressBarSplashScreen() {
JProgressBarSplashScreen splashScreen;
Icon logoIcon = new ImageIcon(getClass().getResource("./images/logo1.jpg"));
JLabel logoLabel = new JLabel(logoIcon);
logoLabel.setBackground(Color.gray);
logoLabel.setOpaque(true);
logoLabel.setBorder(new MatteBorder(5,5,5,5, Color.gray));
logoLabel.setOpaque(true);
splashScreen = new JProgressBarSplashScreen(logoLabel);
splashScreen.iterate();
}

/**
* SplashScreen
*/
public void showSplashScreen() {
Icon logoIcon = new ImageIcon(getClass().getResource("./images/logo.jpg"));
JLabel logoLabel = new JLabel(logoIcon);
logoLabel.setBackground(Color.blue);
logoLabel.setOpaque(true);
logoLabel.setBorder(new MatteBorder(5,5,5,5, Color.gray));
logoLabel.setOpaque(true);
splashScreen = new SplashScreen(logoLabel);
splashScreen.showSplash();
}

/**
* wait splashScreen 10s?
*/
public void WaitSplashScreen() {
while (splashScreen.isVisible()) {
try {
Thread.sleep( 10 );
} catch ( InterruptedException interruptedException ) {
interruptedException.printStackTrace();
}
}
}

/**
* center the login frame
*/
public void CenterOnScreen() {
Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
int width = getSize().width;
int height = getSize().height;
int x = (screenDimension.width - width)/2;
int y = (screenDimension.height - height)/2;
setBounds(x,y,width,height);
}

public void showConInfo() {
conInfo=new AllInformation();
}

/**
* main
*/
public static void main(String args[])
{
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground","true");
try
{
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
catch(UnsupportedLookAndFeelException e)
{
System.out.println ("Metal Look & Feel not supported on this platform. /nProgram Terminated"); System.exit(0);
}

do
{
JPBSS=false;
LogIn login=new LogIn();
login.show();
}
while(JPBSS=false);
}
}

其中connect() 方法是连接数据库的。 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值