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

📄 60cdbb45b8f3001c1ba5970dd0539ecd

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

public class RenShuFrame extends JFrame implements ActionListener{
	JLabel label1 = new JLabel("课程名"); 
	JLabel label2=new JLabel("所选课程总数为 :");
	JLabel label3=new JLabel();
    TextField textField1 = new TextField();
    TextField textField2 = new TextField();
    JButton button1 = new JButton("确定");
    JButton button2 = new JButton("退出");
    Connection conn;
    Statement stmt;
    ResultSet rs;  

    public RenShuFrame() throws Exception
    {
	super("选课人数统计窗口");
	setSize(480,350);
	setLayout(null);
	//setBackground(new Color(110,200,150)); 
	this.setLocation(200,200);
	button1.addActionListener(this);
	button2.addActionListener(this);
	button1.setBounds(45, 205, 83, 23);
	button2.setBounds(175, 205, 83, 23);
	textField1.setBounds(105, 86, 76, 25);
	textField2.setBounds(145, 145, 76, 25);
  	label1.setBounds(45, 86, 57, 19);
  	label2.setBounds(45, 145, 125, 19);
  	label3.setBounds(345,145,100,19);
	add(button1);
	add(button2);
  	add(label1);
  	add(label2);
  	add(label3);
	add(textField1);
	add(textField2);
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	conn = DriverManager.getConnection("jdbc:odbc:student", "", "");
	stmt = conn.createStatement();

	setVisible(true);
      addWindowListener(new WindowAdapter(){
    	  public void windowClosing(WindowEvent e){
    		  dispose();
    		  setVisible(false);
    	  	}
      	}); 
    }
    public void actionPerformed(ActionEvent e)
    {
    	if (e.getSource()==button1)
    	{
    		if(textField1.getText().isEmpty())
    		{
    			label3.setText("输入不能为空");
    		}
    		else{
    			try
    			{
    				String ee = textField1.getText();
    				rs = stmt.executeQuery("select * from xk where 课程名='"+ee+"'");
    				if(rs.next()){
    					textField2.setText(rs.getString("修课人数"));
    				} 
    				else
    					JOptionPane.showMessageDialog(null, "课程不存在!");
    			}
    			catch (Exception eg) {
    				label3.setText("输入错误");
    				eg.printStackTrace();
    			}
    		}

    	}
    	if(e.getSource()==button2)
    	{
    		System.exit(0);
    	}
    	}
     	
}





⌨️ 快捷键说明

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