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

📄 classframe.java

📁 学生成绩管理系统
💻 JAVA
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;

public class ClassFrame extends JFrame{

   
      public ClassFrame(Connection connect){
               
    	  setTitle("Class Manage Frame");
    	  Container c=getContentPane();
  		  c.setLayout(new GridLayout(7,2));
   		
   		jl_cno=new JLabel("class number");
   		jl_cname=new JLabel("class name");
   		jtf_cno=new JTextField("",10);
   		jtf_cname=new JTextField("",10);
   		
   		
   		
   		jb_find=new JButton("find");
   		jb_delete=new JButton("delete");
   		jb_update=new JButton("alter");
   		jb_ok=new JButton("alter_ok");
   		
   		c.add(jl_cno);c.add(jtf_cno);
   		c.add(jl_cname);c.add(jtf_cname);
   		
   		
   		c.add(jb_find);
   		c.add(jb_delete);
   		c.add(jb_update);
   		c.add(jb_ok);
   		
   		
   		con=connect;
   		
   		////////添加响应
   		
   		jb_find.addActionListener(new FindListener());
   		jb_delete.addActionListener(new DeleteListener());
   		jb_update.addActionListener(new UpdateListener() );
   		jb_ok.addActionListener(new OKListener());
   		
   		
   		
   
   }
      
      
      
      
      ////////////响应事件
      class FindListener implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			try{
			
			String s=jtf_cno.getText();
			String sql="select * from class where cno =?";
			PreparedStatement pre=con.prepareStatement(sql);
			pre.setString(1, s);
			rs=pre.executeQuery();
			if(!rs.next()){
				JOptionPane.showMessageDialog(null, "Can not find");
				return;
				}
			jtf_cname.setText(rs.getString(2));
			pre.close();
		   }catch(SQLException e1){
			   JOptionPane.showMessageDialog(null, e1.getMessage());
		   }
		}
    	  
      }
      class DeleteListener implements ActionListener{

  		public void actionPerformed(ActionEvent e) {
  			try{
  				
  				
  				String s=jtf_cno.getText();
  				String sql="delete from class where cno=?";
  				PreparedStatement pre=con.prepareStatement(sql);
  				pre.setString(1, s);
  				if(pre.executeUpdate()!=0)
  				JOptionPane.showMessageDialog(null, "delete successfully!");
  				else
  					JOptionPane.showMessageDialog(null, "delete error!");
  				jtf_cno.setText("");
  				jtf_cname.setText("");
  				
  			}catch(SQLException e1){
 			   JOptionPane.showMessageDialog(null, e1.getMessage());
 		   }
  			
  		}
      	  
        }
      class UpdateListener implements ActionListener{

    		public void actionPerformed(ActionEvent e) {
    			
    			s1=jtf_cno.getText();
    			if(s1.equals("")){
    				JOptionPane.showMessageDialog(null, "Can not Update!");
    				return;
    			}
    				
    			try{
      				String s=jtf_cno.getText();
      				
      				String sql="delete from class where dno=?";
      				PreparedStatement pre=con.prepareStatement(sql);
      				pre.setString(1, s);
      				pre.executeUpdate();
      				
      				
      			}catch(SQLException e1){
     			   JOptionPane.showMessageDialog(null, e1.getMessage());
     		   }
    			
    		}
        	  
          }
      class OKListener implements ActionListener{

      		public void actionPerformed(ActionEvent e) {
      			
      			
      			try{
      				if(jtf_cno.getText().equals("")){
        				JOptionPane.showMessageDialog(null, "Can not Update!");
        				return;
        			}
      				
      				
      				
      				
      				
      				String sql="insert into class values(?,?)";
      				PreparedStatement pre=con.prepareStatement(sql);
      				pre.setString(1, jtf_cno.getText());
      				pre.setString(2, jtf_cname.getText());
      				pre.executeUpdate();
      				JOptionPane.showMessageDialog(null, "update successfully!");
      				
      				
      			}catch(SQLException e1){
     			   JOptionPane.showMessageDialog(null, e1.getMessage());
     		   }
      			
      			
      		}
          	  
            }
    JTextField jtf_cno,jtf_cname;
  	JLabel jl_cno,jl_cname;
  	JButton jb_find,jb_delete,jb_update,jb_ok;
  	
  	
  	Connection con;
  	
  	ResultSet rs;
  	String s1;
   
   
	
}

⌨️ 快捷键说明

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