⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsplashwindow.java

📁 图书管理系统:用户管理
💻 JAVA
字号:
import javax.swing.*;

import java.sql.*;
import java.io.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.sql.DriverManager;
import java.util.*;
import java.net.*;
public class JSplashWindow extends JWindow implements Runnable {
	static final long serialVersionUID=80;
	Thread splashThread = null;
	URL audiourl;
	AudioClip clip;
	public JSplashWindow() {
		File f=new File("skin.dat");
		if(f.exists()){
			try{
				BufferedReader in=new BufferedReader(new FileReader(f));
				String s=in.readLine();
				if(s!=null){
					UIManager.setLookAndFeel(s);
				}
			}
			catch(Exception e3){
				JOptionPane.showMessageDialog(this,e3);
			}
		}
		else{
			try{
				   UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
			   }
			   catch(Exception e3){
				   JOptionPane.showMessageDialog(this,e3);
			   }
		}
		setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
		JPanel splash = new JPanel(new BorderLayout());
		// 获得图片资源的绝对路径
		URL url = getClass().getResource("/images/Login.JPG");  
		if (url != null) { //图片嵌入JLabel中显示
			splash.add(new JLabel(new ImageIcon(url)), BorderLayout.CENTER);
		}
		setContentPane(splash);  // 给启动窗口设置内容窗格
		Dimension screen = getToolkit().getScreenSize(); //获得屏幕的大小
		pack(); 
		//设定启动窗口在屏幕中的位置
		setLocation((screen.width - getSize().width) / 2,
				(screen.height - getSize().height) / 2); 
	}

	public void start() {
		splashThread = new Thread(this);
		splashThread.start();
	}

	public void run() {
		show();
		login();
	}
	private void login(){
		String fileName = "AutoLogin.properties";//记录自动登录要用的服务器名,端口号,用户名,密码
		File file=new File(fileName);
		if(file.exists()){
			try{
				Properties props = new Properties();
				FileInputStream in = new FileInputStream(fileName);
				props.load(in);
				String address=props.getProperty("Address");
				String port=props.getProperty("Port");
				String usertemp=props.getProperty("User");
				String userName="'"+usertemp+"'";
				String passwordtemp=props.getProperty("Password");
				String password="'"+passwordtemp+"'";
				if(address==null||port==null||userName==null||password==null){
					JOptionPane.showMessageDialog(this,"登录失败");
					new LoginFrame("用户登录");
					dispose();
					in.close();
					return;
				}
				try{
					Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
					Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://"+address+":"+port+";DatabaseName=Library","warcrafthero","331310981");
					Statement sql=con.createStatement();
					String query="SELECT UserPurview FROM User_Info WHERE UserName="+userName+" AND UserPassword="+password;
					ResultSet rs=sql.executeQuery(query);
					if(rs.next()){
						String purview=rs.getString(1).trim();
						String uptime="'"+new Timestamp(System.currentTimeMillis()).toString()+"'";
						String s="INSERT INTO User_LoginLog VALUES ("+userName+","+uptime+","+null+")";
						sql.executeUpdate(s);
						new MainFrame("邑大图书管理系统",purview,usertemp,passwordtemp,uptime,con,address,port);
						dispose();
						audiourl=getClass().getResource("/sound/Hi.wav");
						if(audiourl!=null){
							clip=Applet.newAudioClip(audiourl);
							clip.play();
						}
						if(sql!=null){
							sql.close();
						}
						in.close();
						return;
					}
					else{
						JOptionPane.showMessageDialog(this,"用户名或密码错误");
						sleep();
						new LoginFrame("用户登录");
						dispose();
						if(con!=null){
							con.close();
						}
						in.close();
						return;
					}
				}
				catch(ClassNotFoundException e){
					JOptionPane.showMessageDialog(this,e);
					sleep();
					System.exit(0);
				}
				catch(SQLException e2){
					JOptionPane.showMessageDialog(this,"连不上服务器");
					sleep();
					System.exit(0);
				}
			}
			catch(IOException e2){
				JOptionPane.showMessageDialog(this,e2);
				System.exit(0);
			}
		}
		else{
			sleep();
			new LoginFrame("用户登录");
			dispose();
		}
	}
	private void sleep(){
		try{
			Thread.sleep(1500);
		}
		catch(InterruptedException e){
			
		}
	}
	public static void main(String args[]){
		new JSplashWindow().start();
		try{
			Thread.sleep(4000);
		}
		catch(InterruptedException e){
			
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -