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

📄 20fafc62c7f3001c176dbd207e82e608

📁 用于学生资料的管理、成绩的记录、成绩的统计等功能的实现
💻
字号:
package xscj;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

import javax.swing.*;
public class ZongTJFrame extends JFrame implements ActionListener{
	JLabel label1 = new JLabel("学号");
	//Label label2 = new Label("学期");
      JLabel label3=new JLabel("查询结果");
      JLabel label4=new JLabel("");
        JTextField textField1 = new JTextField();
		//TextField textField2 =new TextField();
		JTextField textField3 =new JTextField();
		//textField3.setEditable(false);
		JButton button1 = new JButton("课程数");
		JButton button2 = new JButton("学分数");
		JButton button3 = new JButton("GPA值");
		JButton button4 = new JButton("获优课程数");
		Connection conn;
		Statement stmt;
		ResultSet rs;  
		String strurl;
	public ZongTJFrame() throws Exception
	{
		 super("学期总结窗口");
			setSize(480,400);
			setLayout(null); 
			this.setLocation(200,200);
			button1.addActionListener(this);
			button2.addActionListener(this);
			button3.addActionListener(this);
			button4.addActionListener(this);
			button1.setBounds(20, 226, 83, 23);
			button2.setBounds(115, 226, 83, 23);
			button3.setBounds(205, 226, 83, 23);
			button4.setBounds(295, 226, 110, 23);
			textField1.setBounds(86, 86, 76, 20);
			//textField2.setBounds(225, 86, 76, 20);
			textField3.setBounds(86, 145, 76, 20);
			label1.setBounds(20, 86, 30, 19);
			//label2.setBounds(175, 86, 30, 19);
		   label3.setBounds(20, 145,60, 19);
		  label4.setBounds(175, 145, 100, 19);
		   add(button1);
		   add(button2);
		   add(button3);
		   add(button4);
		   
	    	add(label1);
	//add(label2);
add(label3);
add(label4);
add(textField1);
//add(textField2);
add(textField3);

//add(label4);
//add(label5);
//add(label6);
strurl ="jdbc:odbc:student";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(strurl);
stmt = conn.createStatement();


setVisible(true);
        addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
		dispose();
		setVisible(false);
	}
}); 
}
	
public void actionPerformed(ActionEvent e)
	{
	String str=e.getActionCommand();
	if (str.equals("课程数"))
	{
		if(textField1.getText().equals(""))
		{
			label4.setText("学号不能为空");
		}
		/*else if(textField2.getText().equals(""))
			{
			label4.setText("学期不能为空");
		}*/

		else{
		try
		{
			
          rs = stmt.executeQuery("SELECT * FROM TJ where 学号='"+textField1.getText()+"'");		
	if(rs.next())
	{
	
	
		textField3.setText(rs.getString("课程数"));
	
	
	}
	else{
			JOptionPane.showMessageDialog(null, "记录不存在", "警告",
                            JOptionPane.WARNING_MESSAGE);
		}
	

}
	catch (Exception eg) {

eg.printStackTrace();
}
}
}
	if (str.equals("学分数"))
	{
		if(textField1.getText().equals(""))
		{
			label4.setText("学号不能为空");
		}
		/*else if(textField2.getText().equals(""))
			{
			label4.setText("学期不能为空");
		}*/

		else{
		try
		{
			
          rs = stmt.executeQuery("SELECT * FROM TJ where 学号='"+textField1.getText()+"'");		
	if(rs.next())
	{
	
	
		textField3.setText(rs.getString("学分数"));
	
	
	}
	else{
			JOptionPane.showMessageDialog(null, "记录不存在", "警告",
                            JOptionPane.WARNING_MESSAGE);
		}
	

}
	catch (Exception eg) {

eg.printStackTrace();
}
}
}
	if (str.equals("GPA值"))
	{
		if(textField1.getText().equals(""))
		{
			label4.setText("学号不能为空");
		}
		/*else if(textField2.getText().equals(""))
			{
			label4.setText("学期不能为空");
		}*/

		else{
		try
		{
			
          rs = stmt.executeQuery("SELECT * FROM TJ where 学号='"+textField1.getText()+"'");		
	if(rs.next())
	{
	
	
		textField3.setText(rs.getString("GPA值"));
	
	
	}
	else{
			JOptionPane.showMessageDialog(null, "记录不存在", "警告",
                            JOptionPane.WARNING_MESSAGE);
		}
	

}
	catch (Exception eg) {

eg.printStackTrace();
}
}
}
	if (str.equals("获优课程数"))
	{
		if(textField1.getText().equals(""))
		{
			label4.setText("学号不能为空");
		}
	/*	else if(textField2.getText().equals(""))
			{
			label4.setText("学期不能为空");
		}*/

		else{
		try
		{
			
          rs = stmt.executeQuery("SELECT count(*) FROM COURSE where 学号='"+textField1.getText()+"'");		
	if(rs.next())
	{
	
	
		textField3.setText(rs.getInt(1)+"");
	
	
	}
	else{
			JOptionPane.showMessageDialog(null, "记录不存在", "警告",
                            JOptionPane.WARNING_MESSAGE);
		}
	

}
	catch (Exception eg) {

eg.printStackTrace();
}
}
}	



	}
           	
	}


⌨️ 快捷键说明

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