?? find.java~19~
字號:
package sfms;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class Find extends JFrame implements ActionListener{
JTextField t1;
String STNO,r1,r2,r3,r4,r5,r6;
JButton b1,b2,b3;
Find() {
super("查詢檔案");
Container c1=this.getContentPane();
setBackground(new Color(215, 215, 215));
c1.setLayout(new GridLayout(3,2));
JPanel pp = new JPanel();
pp.add(new Label("請您輸入要查詢的學(xué)生號"));
c1.add(pp);
JPanel p1 = new JPanel();
t1=new JTextField(10);
p1.add(new Label(""));
p1.add(t1);
c1.add(p1);
JPanel p2 = new JPanel();
b1 = new JButton("確定");
b2 = new JButton("清除");
b3 = new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
p2.add(b1);
p2.add(b2);
p2.add(b3);
c1.add(p2);
this.setVisible(true);
this.setSize(400,300);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
shutDown();
}
}
);
}
public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == b1) {
try {
STNO=t1.getText();
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@thsspc0792:1521:SFMS";
Connection cn = DriverManager.getConnection(url, "df", "1234");
String str = "select * from DF.FILEINFO where STNO='" + STNO + "'";
PreparedStatement ps = cn.prepareStatement(str);
ResultSet rs = ps.executeQuery();
System.out.println("STNO="+STNO);
if(rs.next()) {
r1=rs.getString("STNO");
r2=rs.getString("SName");
r3=rs.getString("Gender");
r4=rs.getString("Department");
r5=rs.getString("NativePlace");
r6=rs.getString("TEL");
System.out.println("r1="+r1);
UpdateDialog ud = new UpdateDialog();
ud.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null,"您輸入的學(xué)生號有誤,請重新輸入",
"輸入錯誤",JOptionPane.YES_NO_OPTION);
}
cn.close();
}
catch (SQLException g) {
System.out.println("Error Code: " + g.getErrorCode());
System.out.println("Message=" + g.getMessage());
}
catch (Exception f) {
f.printStackTrace();
}
}
if (e.getSource() == b2) {
t1.setText("");
t1.repaint();
}
if (e.getSource() == b3) {
shutDown();
}
}
catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "數(shù)據(jù)轉(zhuǎn)換錯誤!");
}
}
public void shutDown(){
System.exit(0);
}
class UpdateDialog extends JFrame implements ActionListener {
JTextField tt1, t2, t3, t4, t5, t6;
JButton b4;
UpdateDialog() {
super("查詢學(xué)生檔案");
Container c2 = this.getContentPane();
setBackground(new Color(215, 215, 215));
c2.setLayout(new GridLayout(3, 1));
tt1 = new JTextField(r1);
t2 = new JTextField(r2);
t3 = new JTextField(r3);
t4 = new JTextField(r4);
t5 = new JTextField(r5);
t6 = new JTextField(r6);
tt1.setEditable(false);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
t6.setEditable(false);
JPanel pp1 = new JPanel();
pp1.add(new JLabel("學(xué)號為" + STNO + "學(xué)生的檔案"));
c2.add(pp1);
JPanel pp2 = new JPanel(new GridLayout(6, 2));
pp2.add(new JLabel("學(xué)號"));
tt1.setText(STNO);
pp2.add(tt1);
pp2.add(new JLabel("姓名"));
pp2.add(t2);
pp2.add(new JLabel("性別"));
pp2.add(t3);
pp2.add(new JLabel("系別"));
pp2.add(t4);
pp2.add(new JLabel("地址"));
pp2.add(t5);
pp2.add(new JLabel("電話"));
pp2.add(t6);
c2.add(pp2);
JPanel pp3 = new JPanel(new FlowLayout());
b4 = new JButton("返回");
b4.addActionListener(this);
pp3.add(b4);
c2.add(pp3);
this.setSize(400, 300);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
shutDown2();
}
}
);
}
public void actionPerformed(ActionEvent f) {
if (f.getSource() == b4) {
shutDown2();
}
}
/*
public void up() {
String s1, s2, s3, s4, s5, s6;
s1 = tt1.getText();
s2 = t2.getText();
s3 = t3.getText();
s4 = t4.getText();
s5 = t5.getText();
s6 = t6.getText();
if (s1.length() == 0) {
JOptionPane.showMessageDialog(null, "沒有輸入學(xué)生號");
}
if (s2.length() == 0) {
JOptionPane.showMessageDialog(null, "沒有輸入學(xué)生名");
}
if (s3.length() == 0) {
JOptionPane.showMessageDialog(null, "沒有輸入學(xué)生性別");
}
if (s4.length() == 0) {
JOptionPane.showMessageDialog(null, "沒有輸入學(xué)生系別");
}
if (s5.length() == 0) {
JOptionPane.showMessageDialog(this, "沒有輸入學(xué)生地址");
}
if (s6.length() == 0) {
JOptionPane.showMessageDialog(null, "沒有輸入學(xué)生電話");
}
else {
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:SFMS";
Connection cn = DriverManager.getConnection(url, "df", "1234");
String str = "SELECT SNAME='" + s2 + "'," +
"GENDER='" + s3 + "',DEPARTMENT='" + s4 + "'," +
"NATIVEPLACE='" + s5 + "',TEL='" + s6 + "'"+
" WHERE STNO='" + s1 + "'"+
"FROM DF.FILEINFO ";
PreparedStatement ps = cn.prepareStatement(str);
ps.setString(1, s1);
System.out.println("s1=" + s1);
ps.setString(2, s2);
ps.setString(3, s3);
System.out.println("s2=" + s2);
ps.setString(4, s4);
ps.setString(5, s5);
ps.setString(6, s6);
ResultSet rs=ps.executeQuery(str);
if(rs.next()==false){
JOptionPane.showMessageDialog(null,"沒有您要查詢的學(xué)生");
}
else{
}
cn.close();
JOptionPane.showMessageDialog(null, "更新成功!");
}
catch (SQLException e) {
JOptionPane.showMessageDialog(null, "更新失敗!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
*/
public void shutDown2() {
System.exit(0);
}
}
public static void main(String[] args) {
Find ff = new Find();
ff.setVisible(true);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -