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

📄 mainframe.java

📁 图书管理系统:用户管理
💻 JAVA
字号:
//数据库主界面
import javax.swing.*;

import java.io.*;
import java.applet.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.*;
import java.net.*;
public class MainFrame extends JFrame implements ActionListener{
	static final long serialVersionUID=80;
	JMenuBar menubar;
	JMenu[] menu=new JMenu[7];
	JMenu skinMenu;
	JMenuItem[] item=new JMenuItem[16];
	JMenuItem[] skinItem=new JMenuItem[5];
	Container container;
	JToolBar bar;
	EllipseButton[] button=new EllipseButton[8];
	String purview,user,uptime,address,port,password;
	Toolkit tool;
	MusicFrame frame;
	JPasswordField newtext,confirmtext;
	Image myimage;
	JPanel panel;
	AudioClip audio;
	URL url,bmpurl,audiourl;
	Dimension screenSize;
	JLabel label;
	Statement sql;
	Connection con;
	Color c=new Color(0,150,200,230);
	String connecturl="jdbc:microsoft:sqlserver://"+address+":"+port+";DatabaseName=Library";
	String[] jmenu={"系统管理","数据库管理","图书管理","读书管理","查询","用户管理","帮助"};
	String[] skinString={"java默认","Windows风格","经典苹果主题","office2003","黑红色主题"};
	String[] skinName={"javax.swing.plaf.metal.MetalLookAndFeel","com.sun.java.swing.plaf.windows.WindowsLookAndFeel","com.birosoft.liquid.LiquidLookAndFeel","org.fife.plaf.Office2003.Office2003LookAndFeel","com.sun.java.swing.plaf.motif.MotifLookAndFeel"};
	String[] headers={"登录设置","修改密码","重新登录","退出","数据备份","添加图书","整理图书","读者登记","读者整理","借书","还书","图书查询","读者查询","创建用户","用户整理","关于"};
	MainFrame(String title,String purview,String user,String password,String uptime,Connection con,String address,String port){
		super(title+"   "+user+"已登录");
		tool=getToolkit();
		screenSize=tool.getScreenSize();
		try{
			sql=con.createStatement();
		}
		catch(SQLException e2){
			JOptionPane.showMessageDialog(this,"你已与服务器断开连接");
		}
		url = getClass().getResource("/images/Home.gif");
		if(url!=null){
			myimage=tool.getImage(url);
			setIconImage(myimage);
		}
		this.password=password;
		this.purview=purview;
		this.uptime=uptime;
		this.user=user;
		this.con=con;
		this.address=address;
		this.port=port;
		frame=new MusicFrame("音乐无限");
		container=getContentPane();
		menubar=new JMenuBar();
		setJMenuBar(menubar);
		skinMenu=new JMenu("皮肤");
		skinMenu.setIcon(new ImageIcon(getClass().getResource("/images/icon/skin.png")));
		for(int i=0;i<5;i++){
			skinItem[i]=new JMenuItem(skinString[i]);
			skinItem[i].addActionListener(this);
			skinMenu.add(skinItem[i]);
		}
		for(int i=0;i<7;i++){
			menu[i]=new JMenu(jmenu[i]);
			menubar.add(menu[i]);
		}
		for(int i=0;i<16;i++){
			item[i]=new JMenuItem(headers[i]);
			item[i].addActionListener(this);
			URL iconUrl=getClass().getResource("/images/icon/"+i+".jpg");
			if(iconUrl!=null){
				item[i].setIcon(new ImageIcon(iconUrl));
			}
		}
		menu[0].add(item[0]);
		menu[0].addSeparator();
		menu[0].add(item[1]);
		menu[0].addSeparator();
		menu[0].add(item[2]);
		menu[0].addSeparator();
		menu[0].add(skinMenu);
		menu[0].addSeparator();
		menu[0].add(item[3]);
		menu[1].add(item[4]);
		menu[2].add(item[5]);
		menu[2].addSeparator();
		menu[2].add(item[6]);
		for(int i=7;i<11;i++){
			menu[3].add(item[i]);
			if(i<10){
				menu[3].addSeparator();
			}
		}
		menu[4].add(item[11]);
		menu[4].addSeparator();
		menu[4].add(item[12]);
		menu[5].add(item[13]);
		menu[5].addSeparator();
	    menu[5].add(item[14]);
		menu[6].add(item[15]);
		bar=new JToolBar();
		bar.setBackground(c);
		for(int i=0;i<8;i++){
			URL imageurl=getClass().getResource("/images/"+i+".gif");
			if(imageurl!=null){
				ImageIcon icon=new ImageIcon(imageurl);
				button[i]=new EllipseButton(icon);
				if(i==7){
					button[i].setToolTipText("音乐无限");
				}
				else{
					button[i].setToolTipText(headers[i+4]);
				}
			}
			else{
				button[i]=new EllipseButton(headers[i+4]);
			}
			button[i].addActionListener(this);
			button[i].setBackground(c);
			bar.add(button[i]);
		}
		container.add(bar,BorderLayout.NORTH);
		label=new JLabel(new ImageIcon("images/白桦树中林荫道.JPG"));
		container.add(label,BorderLayout.CENTER);
		setSize(screenSize.width*3/4,screenSize.height*5/6);
		setLocation((screenSize.width - this.getSize().width) / 2,(screenSize.height - this.getSize().height) / 2);
		validate();
		setVisible(true);
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				int n=JOptionPane.showConfirmDialog(null,"你确定要退出?","确定对话框",JOptionPane.YES_NO_OPTION);
				if(n==JOptionPane.YES_OPTION){
					audiourl=getClass().getResource("/sound/Bye.wav");
					if(audiourl!=null){
						audio=Applet.newAudioClip(audiourl);
						audio.play();
					}
					try{
						Thread.sleep(500);
					}
					catch(InterruptedException e1){
						
					}
					saveDownTime();
					System.exit(0);
				}
			}
		});
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==item[0]){
			new SetAutoLoginFrame("登录设置",this);
		}
	    else if(e.getSource()==item[1]){
			new PasswordFrame("修改密码",user,con);
		}
		else if(e.getSource()==item[2]){
			int n=JOptionPane.showConfirmDialog(this,"退出重新登录?","确认对话框",JOptionPane.YES_NO_OPTION);
			if(n==JOptionPane.YES_OPTION){
				audiourl=getClass().getResource("/sound/Bye.wav");
				if(audiourl!=null){
					audio=Applet.newAudioClip(audiourl);
					audio.play();
				}
				saveDownTime();
				try{
					con.close();
					sql.close();
				}
				catch(SQLException e1){
					System.out.println("已经断开");
				}
				new LoginFrame("用户登录");
				dispose();
			}
		}
		else if(e.getSource()==item[3]){
			int n=JOptionPane.showConfirmDialog(this,"退出?","确认对话框",JOptionPane.YES_NO_OPTION);
			if(n==JOptionPane.YES_OPTION){
				saveDownTime();
				System.exit(0);
			}
		}
		else if(e.getSource()==item[4]){
			if(purview.equals("System")){
				new BackupFrame("备份",con);
			}
			else{
				JOptionPane.showMessageDialog(this,"你没有权限使用备份数据库功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
		}
		else if(e.getSource()==item[5]||e.getSource()==button[0]){
			if(purview.equals("Common")||purview.equals("Borrow")){
				JOptionPane.showMessageDialog(this,"你没有权限使用添加新书功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
			else{
				new AddOrChangeBookFrame("添加新书",con,false,null,null);
			}
		}
		else if(e.getSource()==item[6]||e.getSource()==button[1]){
			if(purview.equals("Common")||purview.equals("Borrow")){
				JOptionPane.showMessageDialog(this,"你没有权限使用整理图书功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
			else{
				try{
					new TidyBookOrReaderFrame("图书整理",con,purview,true);
				}
				catch(InterruptedException e3){
					
				}
			}
		}
		else if(e.getSource()==item[7]||e.getSource()==button[2]){
			if(purview.equals("Common")||purview.equals("Book")){
				JOptionPane.showMessageDialog(this,"你没有权限使用登记读者功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
			else{
				new AddOrChangeReaderFrame("登记读者",true,con,null,null);
			}
		}
		else if(e.getSource()==item[8]||e.getSource()==button[3]){
			if(purview.equals("Common")||purview.equals("Book")){
				JOptionPane.showMessageDialog(this,"你没有权限使用整理读者信息功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
			else{
				try{
					new TidyBookOrReaderFrame("读者整理",con,purview,false);
				}
				catch(InterruptedException e3){
					
				}
			}
		}
		else if(e.getSource()==item[9]||e.getSource()==button[4]){
			if(purview.equals("Common")||purview.equals("Book")){
				JOptionPane.showMessageDialog(this,"你没有权限使用借书功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
			else{
				new LendOrBorrowFrame("借书",true,con);
			}
		}
		else if(e.getSource()==item[10]||e.getSource()==button[5]){
			if(purview.equals("Common")||purview.equals("Book")){
				JOptionPane.showMessageDialog(this,"你没有权限使用还书功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
			else{
				new LendOrBorrowFrame("还书",false,con);
			}
		}
		else if(e.getSource()==item[11]||e.getSource()==button[6]){
			try{
				new TidyBookOrReaderFrame("图书查询",con,purview,true);
			}
			catch(InterruptedException e3){
				
			}
		}
		else if(e.getSource()==button[7]){
			frame.setVisible(true);
		}
		else if(e.getSource()==item[12]){
			if(purview.equals("System")||purview.equals("Borrow")){
				try{
					new TidyBookOrReaderFrame("读者查询",con,purview,false);
				}
				catch(InterruptedException e3){
					
				}
			}
			else{
				JOptionPane.showMessageDialog(this,"你没有权限使用读者查询功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
		}
		else if(e.getSource()==item[13]){
			if(purview.equals("System")){
				new AddOrChangeUser("创建用户",con,true,null,null);
			}
			else{
				JOptionPane.showMessageDialog(this,"你没有权限使用创建用户功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
		}
		else if(e.getSource()==item[14]){
			if(purview.equals("System")){
				new TidyUserFrame("用户整理",con);
			}
			else{
				JOptionPane.showMessageDialog(this,"你没有权限使用用户整理功能","警告对话框",JOptionPane.WARNING_MESSAGE);
			}
		}
		else if(e.getSource()==item[15]){
			new AboutFrame("关于邑大数据库管理系统");
		}
		else{
			for(int i=0;i<5;i++){
				if(e.getSource()==skinItem[i]){
					dispose();
					try{
						UIManager.setLookAndFeel(skinName[i]);
						File f=new File("skin.dat");
						if(f.exists()){
							f.delete();
						}
						BufferedWriter out=new BufferedWriter(new FileWriter(f));
						out.write(skinName[i],0,skinName[i].length());
						out.flush();
						out.close();
					}
				    catch(Exception e2){
				    	JOptionPane.showMessageDialog(this,e2);
				    }
				    new MainFrame("邑大图书管理系统",purview,user,password,uptime,con,address,port);
				    break;
				}
			}
		}
	}
	//向数据库提交离开时间
	private void saveDownTime(){
		String s="'"+user+"'";
		String t="'"+new Timestamp(System.currentTimeMillis()).toString()+"'";
		String queue="UPDATE User_LoginLog SET DownTime = "+t+" WHERE UserName = "+s+" AND UpTime = "+uptime;
		try{
			sql.executeUpdate(queue);
		}
		catch(SQLException e){
			JOptionPane.showMessageDialog(this,"计算机已与服务器断开");
		}
	}
}

⌨️ 快捷键说明

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