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

📄 find.java

📁 java实现简易的教学管理系统
💻 JAVA
字号:

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;


public class Find extends JFrame implements ActionListener{
  JTextField t1;
  //JTextArea textT;
  String r1,r2,r3,r4,r5,r6,r7,r8;
  JButton b1,b2,b3;
  MainWindow parent1;
  Find(MainWindow window) {
    super("查询学生信息");
    parent1=window;
    Container c1=this.getContentPane();
    setBackground(new Color(125, 215, 215));
    c1.setLayout(new GridLayout(3,1));
    JPanel pp = new JPanel();
    JLabel label0=new JLabel("请您输入要查询的学生号");
    label0.setForeground(Color.red);
    label0.setFont(new Font("TRUE",Font.TRUETYPE_FONT,25));
    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.setLocation(200,200);
    
    //////////////////关闭窗口
    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
        shutDown();
      }
    }
    );
  }
  //////////////////////////////////////////////////事件监听
public void actionPerformed(ActionEvent e) {
    try {
      if (e.getSource() == b1){
        try {
          r1=t1.getText();
  
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  String url = "jdbc:odbc:STU";
  Connection cn = DriverManager.getConnection(url,"sa","");
  
    String STUDENT = "select * from student where student.Sno='" + r1 + "'";
    String COURSE  = "select * from course where course.Sno = '"+ r1 +"'";
     
//String str = "select Sno,Sname,Ssex,Sclass, java,C,data,opsystem from student,course where course.Sno = student.Sno and student.Sno = '"+ r1 +"' ";
   
   
  Statement ps1 = cn.createStatement();///////////////////////
  ResultSet rs1 = ps1.executeQuery(STUDENT);
  
   
  System.out.println("Sno="+r1);
  if(rs1.next()) {
  	
    r1=rs1.getString("Sno");
    r2=rs1.getString("Sname");
    r3=rs1.getString("Ssex");
    r4=rs1.getString("Sclass");
    File ud = new File(this);
    ud.setVisible(true);

   }
   
   ps1 = cn.createStatement();
   rs1 = ps1.executeQuery(COURSE);
  
    
   if(rs1.next()){
   
    r5=rs1.getString("java");
    r6=rs1.getString("C");
    r7=rs1.getString("data");
    r8=rs1.getString("opsystem");
    
    File ud = new File(this);
    ud.setVisible(true);
    

  }
  else {
    JOptionPane.showMessageDialog(null,"您输入的学生号有误,请重新输入",
     "输入错误",JOptionPane.YES_NO_OPTION);
  }
  cn.close();
}


catch (SQLException g) {
  JOptionPane.showMessageDialog(null,g.getMessage(),
                       "数据库查找异常!",JOptionPane.ERROR_MESSAGE);
  }

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 t1, t2, t3, t4 , t5 , t6 , t7 , t8;
   JButton b4;
   Find parent2;
   File(Find f2) {
     super("查询学生信息");
     parent2=f2;
     Container c2 = this.getContentPane();
     setBackground(new Color(215, 215, 215));
     c2.setLayout(new GridLayout(8, 1));
     t1 = new JTextField(r1);
     t2 = new JTextField(r2);
     t3 = new JTextField(r3);
     t4 = new JTextField(r4);
     t5 = new JTextField(r5);
     t6 = new JTextField(r6);
     t7 = new JTextField(r7);
     t8 = new JTextField(r8);
     
     t1.setEditable(false);
     t2.setEditable(false);
     t3.setEditable(false);
     t4.setEditable(false);
     t5.setEditable(false);
     t6.setEditable(false);
     t7.setEditable(false);
     t8.setEditable(false);
     
     JPanel pp1 = new JPanel();
     JLabel label = new JLabel();
     label.setForeground(Color.blue);
     label.setFont(new Font("TRUE",Font.TRUETYPE_FONT,25));
     
     pp1.add(new JLabel("学号为" + r1 + "学生的信息"));
     c2.add(pp1);
     JPanel pp2 = new JPanel(new GridLayout(2, 1));/////////////////////////////
     
     //pp2.add(new JLabel("学号",SwingConstants.CENTER));
     //t1.setText(r1);
     
     pp2.add(new JLabel("学号",SwingConstants.CENTER));
     pp2.add(t1);
     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("java",SwingConstants.CENTER));
     pp2.add(t5);
     pp2.add(new JLabel("C",SwingConstants.CENTER));
     pp2.add(t6);
     pp2.add(new JLabel("数据库",SwingConstants.CENTER));
     pp2.add(t7);
     pp2.add(new JLabel("系统",SwingConstants.CENTER));
     pp2.add(t8);
     
     c2.add(pp2);
     JPanel pp3 = new JPanel(new FlowLayout());
     b4 = new JButton("返回");
     b4.addActionListener(this);
     pp3.add(b4);
     c2.add(pp3);
     this.setSize(500, 500);
     this.setLocation(200,200);
     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();
   }
 }

 }

⌨️ 快捷键说明

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