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

📄 testframe.java

📁 这是一个关于jsp的学习文档.为学习jsp的朋友提供方便
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class TestFrame{
    public static void main(String[] args) {
        Frame f = new Frame("Login Test");
        Label label = new Label("Please input your name and password");
        label.setForeground(Color.white);
        TextField tfName = new TextField("");
        TextField tfPassword = new TextField("");
        Button button = new Button("Login");
        f.setLayout(new GridLayout(4,1));
        f.add(label);
        f.add(tfName);
        f.add(tfPassword);
        f.add(button);
        button.addActionListener(new MyActionListener(tfName,tfPassword,label));
        f.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e) {
                System.exit(0);	
            }	
        }); 
        f.setSize(300,200);
        f.setBackground(Color.blue);
        f.setVisible(true);
    }	
}

class MyActionListener implements ActionListener{
    private TextField tfName;
    private TextField tfPassword;
    private Label label;
    boolean flag = false;
    
    public MyActionListener(TextField tfName,TextField tfPassword,Label label) {
        this.tfName = tfName;
        this.tfPassword = tfPassword;
        this.label  = label;	
    }
	
	public void actionPerformed(ActionEvent e) {
		String serverName = "localhost";
		flag = false;
		try{
		   /* Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();    
		      String  url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";    
                   */
 
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  //注册驱动程序 
			Connection conn = DriverManager.getConnection("jdbc:odbc:sql", "", "");   
                  
                    String sql="select * from account where username='" + tfName.getText() + "'";
		    sql +=" and password='" + tfPassword.getText() + "'";
            
		    Statement stmt=conn.createStatement();
		    ResultSet rs=stmt.executeQuery( sql );
		    if( rs.next() ) flag = true;
		}catch(Exception ee){
		    ee.printStackTrace();
		}
		if(flag) label.setText("OK!");
		else     label.setText("Fail!"); 
	}
}

⌨️ 快捷键说明

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