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

📄 find.java

📁 基于java的学生信息管理系统的开发与应用
💻 JAVA
字号:
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;
  mainWindow parent1;
  Find(mainWindow window) {
    super("查询学生信息");
    parent1=window;
    Container c1=this.getContentPane();
    setBackground(new Color(215, 215, 215));
    c1.setLayout(new GridLayout(3,2));
    JPanel pp = new JPanel();
    JLabel label0=new JLabel("请您输入要查询的学生号");
    label0.setForeground(Color.blue);
    label0.setFont(new Font("TRUE",Font.TRUETYPE_FONT,20));
    pp.add(label0);
    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");
    File ud = new File(this);
    ud.setVisible(true);

  }
  else {
    JOptionPane.showMessageDialog(null,"您输入的学生号有误,请重新输入",
     "输入错误",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, "数据转换错误!");
    }
  }
 public void shutDown(){
     parent1.setVisible(true);
     this.dispose();
 }
class File extends JFrame implements ActionListener {
   JTextField tt1, t2, t3, t4, t5, t6;
   JButton b4;
   Find parent2;
   File(Find f2) {
     super("查询学生信息");
     parent2=f2;
     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("学号为" + STNO + "学生的信息"));
     c2.add(pp1);
     JPanel pp2 = new JPanel(new GridLayout(6, 2));
     pp2.add(new JLabel("学号",SwingConstants.CENTER));
     tt1.setText(STNO);
     pp2.add(tt1);
     pp2.add(new JLabel("姓名",SwingConstants.CENTER));
     pp2.add(t2);
     pp2.add(new JLabel("性别",SwingConstants.CENTER));
     pp2.add(t3);
     pp2.add(new JLabel("系别",SwingConstants.CENTER));
     pp2.add(t4);
     pp2.add(new JLabel("地址",SwingConstants.CENTER));
     pp2.add(t5);
     pp2.add(new JLabel("电话",SwingConstants.CENTER));
     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 shutDown2() {
    parent2.setVisible(true);
    this.dispose();
   }
 }
 /*    public static void main(String[] args) {

         Find ff = new Find();
         ff.setVisible(true);
       }
      */
 }

⌨️ 快捷键说明

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