?? 1.學生登錄界面.txt
字號:
package library;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
import java.lang.String;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import java.awt.Font;
import java.sql.*;
import javax.swing.*;
public class Frame1 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
Connection conn;
JOptionPane jOptionPane1 = new JOptionPane();
JLabel jLabel3 = new JLabel();
public Frame1()
{
try
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
public void jbInit() throws Exception
{
try //try 和 catch 用于鏈接數據庫
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//安裝驅動
String connURL ="jdbc:odbc:library"; //library為數據庫名稱
String user = "sa";
String pw = "123";
conn=DriverManager.getConnection(connURL,user,pw);//前面已經定義coon
}
catch(Exception e)
{
System.out.println("class no found can not connect to sql server"+e);
} //數據庫鏈接完畢
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
closeWindow(e);
}
});
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(300, 200));
setTitle("讀者登陸界面");
jLabel1.setFont(new java.awt.Font("宋體", Font.PLAIN, 20));
jLabel1.setText("ID");
jLabel2.setFont(new java.awt.Font("宋體", Font.PLAIN, 20));
jLabel2.setText("密碼");
jButton1.setText("登陸");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jTextField1.addActionListener(new Frame1_jTextField1_actionAdapter(this));
jTextField1.setToolTipText("");
jTextField1.setText("200511621223");
jLabel3.setText("設計小組:謝嘉任 張淅茗");
jPasswordField1.setText("200511621223");
contentPane.add(jLabel1, new XYConstraints(41, 29, -1, -1));
contentPane.add(jLabel2, new XYConstraints(32, 81, -1, -1));
contentPane.add(jOptionPane1, new XYConstraints(372, 196, -1, -1));
contentPane.add(jLabel3, new XYConstraints(33, 144, -1, -1));
contentPane.add(jPasswordField1, new XYConstraints(102, 83, 137, -1));
contentPane.add(jTextField1, new XYConstraints(102, 30, 137, 25));
contentPane.add(jButton1, new XYConstraints(130, 113, 68, -1));
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
public void jButton1_actionPerformed(ActionEvent e)
{
F1();
}
void F1(){
try
{
String str1,str2;
str1=jTextField1.getText();
str2=new String(jPasswordField1.getPassword());
Statement pstmt1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql= "select * from reader where ID='"+str1+"' AND 密碼 = '"+str2+"' ";
ResultSet rs2 = pstmt1.executeQuery(sql);
if (!rs2.next())
{
JOptionPane.showMessageDialog(this,"帳號或者密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);
}
else
{
Frame2 f=new Frame2();
f.setVisible(true);
pstmt1.close();
}
dispose();
}
catch(Exception e)
{
System.err.println(e);
}
} //F1()
void closeWindow(WindowEvent e)
{
int intok = JOptionPane.showConfirmDialog(this,"確定要退出系統嗎?","提示",JOptionPane.OK_OPTION);
if(intok == 0)
{
try
{
}
catch(Exception e1)
{
System.out.println("can't to close"+e1);
}
System.exit(0);
}
else
{return;}
}
public void jTextField1_actionPerformed(ActionEvent e)
{
}
}
class Frame1_jTextField1_actionAdapter implements ActionListener
{
private Frame1 adaptee;
Frame1_jTextField1_actionAdapter(Frame1 adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jTextField1_actionPerformed(e);
}
}
class Frame1_jButton1_actionAdapter implements ActionListener
{
private Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -