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

📄 login.java

📁 用java编写的图书馆管理程序
💻 JAVA
字号:
package bookmanager;

import java.awt.*;
import java.sql.*;

import javax.swing.*;



import java.awt.event.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Login extends JDialog {
	JLibrary myMain;
	private ResultSet rs;
	//for creating the North Panel
    private JPanel northPanel = new JPanel();
 //for creaing the North Label
    private JLabel northLabel = new JLabel("USER LOGIN");
 
 //for creating the Center Panel
    private JPanel centerPanel = new JPanel();
 //for creating an Internal Panel in the center panel
    private JPanel informationLabelPanel = new JPanel();
 
 //for creating an array of JLabel
    private JLabel[] informationLabel = new JLabel[2];
 //for creating an array of String
    private String[] informationString = {
       "UserName: ","Password: ",
     
    };
 //for creating an Internal Panel in the center panel
    private JPanel informationPanel = new JPanel();
 //for creating a JTextField
    private JTextField informationTextField = new JTextField();
  //for creating a JPasswordField
    private JPasswordField informationPasswordField = new JPasswordField();
    
 //for creating an Internal Panel in the center panel
  //  private JPanel insertInformationButtonPanel = new JPanel();
 //for creating a button
   // private JButton insertInformationButton = new JButton("Insert the Information");
    private JPanel insertInformationButtonPanel = new JPanel();
 //for creating South Panel
    private JPanel southPanel = new JPanel();
 //for creating buttons
    private JButton OKButton=new JButton("OK");
    private JButton ExitButton = new JButton("Exit");
 
 //create objects from another classes for using them in the ActionListener
    private toDatabase dataToDatabase;
 //for creating an array of string to store the data
    private String[] data;
 //for setting availble option to true
    private boolean availble = true;
    
    public boolean isCorrect() {
        data = new String[5];
        for(int i = 0; i < informationLabel.length; i++) {
           if(i == 0) {
              if(! informationTextField.getText().trim().equals("")) {
                 data[i] = informationTextField.getText().trim();
              }//if2	
              else
                 return false;
           	}//if1	
           if(i == 1 ) {
              if(new String(informationPasswordField.getPassword()).equals(""))
                 return false;
              else data[i]=informationPasswordField.getText().trim();
           }//if3
         
      }//for
        
        return true;
     }//isCorrect
	public Login(Frame frame, String title, boolean modal) {
	    super(frame,title,modal);
	    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	    setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
	    try {
	      Init();
	    }
	    catch (Exception ex) {
	      ex.printStackTrace();
	    }
	}
	public static void main(String args[]) {
		try {
			Login frame = new Login();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	public Login() {
		this(null, "", false);
		//setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Export24.gif")));
		//setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Export24.gif")));
	}
	  public Login(JLibrary bMain) {
		  
		    this(null, "", false);
		    setSize(350, 220);
		   // setSize(new Dimension(350, 220));
		    myMain = bMain;
		  }
	public void Init(){	
		Container cp = getContentPane();
		
		  //for setting the layout
        northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
     //for setting the font
        northLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
     //for adding the label to the panel
        northPanel.add(northLabel);
     //for adding the panel to the container
        cp.add("North", northPanel);
     
     //for setting the layout
        centerPanel.setLayout(new BorderLayout());
     //for setting the border to the panel
        centerPanel.setBorder(BorderFactory.createTitledBorder("User Login:"));
     //for setting the layout
        informationPanel.setLayout(new GridLayout(6,2,1,1));
        for(int i = 0; i < informationLabel.length; i++) {
        informationPanel.add(informationLabel[i]= new JLabel(informationString[i]));
        informationLabel[i].setFont(new Font("Tahoma", Font.BOLD, 11));   
        if(i == 1){
        	informationPanel.add(informationPasswordField = new JPasswordField(20));
            informationPasswordField.setFont(new Font("Tahoma", Font.PLAIN, 11));
        }
        if(i == 0) {
            informationPanel.add(informationTextField = new JTextField(20));
            informationTextField.setFont(new Font("Tahoma", Font.PLAIN, 11));
         }
        }   
        centerPanel.add("Center", informationPanel);
        insertInformationButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
        OKButton.setFont(new Font("Tahoma", Font.BOLD, 11));
        insertInformationButtonPanel.add(OKButton);
        centerPanel.add("South", insertInformationButtonPanel);
        cp.add("Center", centerPanel);
        
        southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
        ExitButton.setFont(new Font("Tahoma", Font.BOLD, 11));
        ExitButton.addMouseListener(new MouseAdapter() {
        	public void mouseClicked(MouseEvent arg0) {
        		handleExitButtonMouseClicked(arg0);
        	}
        });
        southPanel.add(ExitButton);
        southPanel.setBorder(BorderFactory.createEtchedBorder());
        cp.add("South", southPanel);
       OKButton.addActionListener(
                new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                	   
                   //for checking if there is a missing information
                      if(isCorrect()) {
                         
                            Thread runner = 
                               new Thread() {
                                  public void run() {
                                     dataToDatabase = new toDatabase();
                                  //for checking if there is no same information in the database
                               String Levell=dataToDatabase.isVerityUser("select * from operater where username='"+data[0]+"' and password='"+data[1]+"'");
                               myMain.setEnable(Levell);
               		        dispose();   
		   
              }
		    
                                  
                                 
                             };
                             runner.start();
                            }//isCorrect
                      }//OKButton actionPerformed
                   });//thread
       }
	protected void handleExitButtonMouseClicked(MouseEvent e) {
		this.dispose();
	}
	}//login

⌨️ 快捷键说明

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