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

📄 land.java

📁 实现奖学金的评定
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.table.*;
import java.sql.ResultSet;
import java.io.*;
class Land extends JFrame implements ActionListener {
	JFrame jf ;
	Connection con;
    Statement stmt;
    ResultSet rs;
	JTextField textName=new JTextField();
	JPasswordField textage=new JPasswordField();
	JLabel label = new JLabel("奖学金评定系统");
	JLabel labelName=new JLabel("用户名:");
	JLabel labelage=new JLabel("密 码:");


	JButton buttonEnter=new JButton("登录");
	JButton buttoncancel=new JButton("退出");

	public Land(){

		this.setSize(300,200);
		this.setLocation(350,300);
		setTitle("登录");
		Font f = new Font("新宋体",Font.PLAIN,12);
		Container cn = getContentPane();
		cn.setLayout(null);
		label.setBounds(95,10,110,20);
		label.setFont(new Font("新宋体",Font.PLAIN,14));
		cn.add(label);
		labelName.setBounds(45,40,55,20);
		labelName.setFont(f);
		cn.add(labelName);
		textName.setBounds(95,40,120,20);
		cn.add(textName);
        labelage.setBounds(45,70,45,20);
		cn.add(labelage);
		labelage.setFont(f);
     	textage.setBounds(95,70,120,20);
		cn.add(textage);
        buttonEnter.setBounds(90,110,60,20);
		buttonEnter.setFont(f);
		cn.add(buttonEnter);
		buttoncancel.setBounds(155,110,60,20);
		buttoncancel.setFont(f);
		cn.add(buttoncancel);
		buttonEnter.addActionListener(this);
		buttoncancel.addActionListener(this);
        this.connection();
		this.setVisible(true);}
	    public void actionPerformed(ActionEvent e) {
			
    	if(e.getSource()==buttonEnter)
        {  
  		try{
            rs=stmt.executeQuery("select * from user1");
        	String user="";
            String passward="";
        	rs.next();
               user=rs.getString(1);
        	   passward=rs.getString(2);
            char temp[] = textage.getPassword();
            String tempPass =new String(temp);
        	if((textName.getText().equals(user))&&(tempPass.equals(passward)))
        	      {this.setVisible(false);
        	       new mainframe(); 
        	      }
        	      
        	 else
        	      {
        	      	new JOptionPane().showMessageDialog(null,"无效的用户名或密码!");
        	        textName.setText("");
        	        textage.setText("");
        	      }
        	      
        }
        catch(Exception ea)
        {System.out.println(ea.getMessage());}
    }
   if (e.getSource() == buttoncancel) 
        { 
                       System.exit(0);
        }

        }
        public void connection(){
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con=DriverManager.getConnection("jdbc:odbc:user");
        stmt = con.createStatement();
        
    } catch (Exception ex) {
    	System.out.println(ex.getMessage());
    }
    }
    

	}

⌨️ 快捷键说明

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