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

📄 teachermainframe.java

📁 学生管理系统
💻 JAVA
字号:
/**
 *@author weiWang
 *@Date 2006-3-27
 *@TeacherFrame.java
 */
 //老师操作的面版设置
 
 package com.herb.teacherclient; 
 
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import javax.swing.table.*;
 import java.util.*;
 
 public class TeacherMainFrame extends JFrame{
    JButton resetBtn;
    JMenuBar bar=new JMenuBar();
    JMenu fileMenu=new JMenu("文件");
    JMenu chatMenu=new JMenu("聊天");
    JMenu ipsetMenu=new JMenu("设置");
    JMenuItem ipsetMenuItem=new JMenuItem("IP设置");
    JMenuItem chatItem=new JMenuItem("打开聊天器");
    JMenuItem getMajorItem=new JMenuItem("导入信息");
    JMenuItem exitItem=new JMenuItem("退出"); 
    JSplitPane displayPanel=new JSplitPane(); 
    static JList list; 
    static DefaultListModel listModel;
    static int listRow=0;
    static DefaultTableModel m;
    static JTable table;
    static Object[][] data;
    static String[] name={"学号","姓名","性别","系名","班级","课程","成绩","联系电话"}; 
    private static final String CODE1="001";  //导入系名的代号
    private static final String CODE2="002";  //导入学生信息代号
  
    public TeacherMainFrame(){
        super("学生信息管理系统");
        Container content=this.getContentPane();
        content.setLayout(new BorderLayout(5,5));        
        initMenu();  
        initPanel();
        content.add("Center",displayPanel);
        
        content.add("North",bar);
        content.add("West",new JLabel("")); 
        content.add("East",new JLabel(""));
        content.add("South",new JLabel(""));
        setVisible(true);
        pack();
        LocationSet.setFrameLocation(this);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
    
    public void initMenu(){
        fileMenu.add(getMajorItem); 
        getMajorItem.addActionListener(new ActionListener(){ 
           public void actionPerformed(ActionEvent e){
               ClientPart client=new ClientPart(CODE1);    
               Thread t=new Thread(client);
               t.start(); 
           }
        });
        fileMenu.add(exitItem);
        exitItem.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               System.exit(0);
           }
        });
        chatMenu.add(chatItem);
        chatItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
               ChatLogFrame chatLogFrame=new ChatLogFrame();
               LocationSet.setFrameLocation(chatLogFrame);
            }
        });
        ipsetMenu.add(ipsetMenuItem);
        ipsetMenuItem.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
               ipsetEvent();
             }
        });
        bar.add(fileMenu);
        bar.add(chatMenu);
        bar.add(ipsetMenu);
    }
       
    public void initPanel(){
      JPanel btnPanel=new JPanel();
      JPanel tablePanel=new JPanel();   //include btnPanel
      data=new Object[0][name.length];    //测试用
      
      JButton paixuBtn1=new JButton("按学号排序",new ImageIcon("com/herb/teacherclient/icons/paixu1.gif"));
      paixuBtn1.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
                arrayByStudentId();
                resetBtn.setEnabled(false);
          }
      });   
      paixuBtn1.setPreferredSize(new Dimension(110,27));
      paixuBtn1.setBackground(new Color(225,234,253));
      paixuBtn1.setForeground(new Color(71,30,5));
      paixuBtn1.setPreferredSize(new Dimension(110,27));

      JButton paixuBtn2=new JButton("按成绩排序",new ImageIcon("com/herb/teacherclient/icons/paixu2.gif"));
      paixuBtn2.setBackground(new Color(225,234,253));
      paixuBtn2.setForeground(new Color(71,30,5));
      paixuBtn2.setPreferredSize(new Dimension(110,27));
      paixuBtn2.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
                arrayByStudentMark();
                resetBtn.setEnabled(false);
          }
      });
      paixuBtn2.setPreferredSize(new Dimension(110,27));
      JButton paixuBtn3=new JButton("按课程排序",new ImageIcon("com/herb/teacherclient/icons/paixu3.gif"));
      paixuBtn3.setBackground(new Color(225,234,253));
      paixuBtn3.setForeground(new Color(71,30,5));
      paixuBtn3.setPreferredSize(new Dimension(110,27));
      paixuBtn3.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
                arrayByStudentLesson();
                resetBtn.setEnabled(false);
          }
      });
      paixuBtn3.setPreferredSize(new Dimension(110,27));
      resetBtn=new JButton("修改成绩",new ImageIcon("com/herb/teacherclient/icons/reset.gif"));  
      resetBtn.setPreferredSize(new Dimension(110,27));
      btnPanel.add(paixuBtn1);
      btnPanel.add(paixuBtn2);
      btnPanel.add(paixuBtn3);
      btnPanel.add(resetBtn);
      resetBtn.addActionListener(new ActionListener(){ 
         public void actionPerformed(ActionEvent e){
             resetMark();          //修改分数
         }
      });
      
      listModel=new DefaultListModel();      
      list=new JList(listModel);
      list.setForeground(Color.blue);
      list.setSelectionBackground(new Color(227,238,253));
      list.setSelectionForeground(new Color(180,121,24));
      list.setFont(new Font("宋体",Font.PLAIN,12));
      list.addMouseListener(new MouseAdapter(){
        public void mouseClicked(MouseEvent me){
           if(me.getClickCount()==2){
              resetBtn.setEnabled(true);
              ClientPart c=new ClientPart(CODE2,String.valueOf(list.getSelectedValue()));
              Thread ct=new Thread(c);
              ct.start();
           }
        }
      });
      JPanel listPanel=new JPanel();
      listPanel.setLayout(new BorderLayout());
      listPanel.add("Center",new JScrollPane(list));
      listPanel.setPreferredSize(new Dimension(140,200));
      listPanel.setBorder(BorderFactory.createTitledBorder("系名列表:"));
      m=new DefaultTableModel(data,name);        
      table=new JTable(m);
      table=new JTable(m);
        //设置各列宽度
        TableColumn column;
        column=table.getColumnModel().getColumn(0); 
        column.setPreferredWidth(100);
        column=table.getColumnModel().getColumn(1);
        column.setPreferredWidth(45);
        column=table.getColumnModel().getColumn(2);
        column.setPreferredWidth(15);
        column=table.getColumnModel().getColumn(3);
        column.setPreferredWidth(80);
        column=table.getColumnModel().getColumn(4);
        column.setPreferredWidth(45);
        column=table.getColumnModel().getColumn(5);
        column.setPreferredWidth(85);
        column=table.getColumnModel().getColumn(6);
        column.setPreferredWidth(14);
        column=table.getColumnModel().getColumn(7);
        column.setPreferredWidth(150);
        table.setFont(new Font("宋体",Font.PLAIN,12));
        table.setGridColor(new Color(31,86,216)); 
        table.setSelectionBackground(new Color(239,227,253));
        table.setSelectionForeground(new Color(253,29,11));
      tablePanel.setLayout(new BorderLayout(0,8));
      tablePanel.add("Center",new JScrollPane(table));
      tablePanel.add("South",btnPanel);
      tablePanel.setPreferredSize(new Dimension(700,580));
      listPanel.setPreferredSize(new Dimension(140,400));
      displayPanel.add(tablePanel,JSplitPane.RIGHT);
      displayPanel.add(listPanel,JSplitPane.LEFT);
      displayPanel.setDividerSize(5);
    }
  
    //按字符串排序
    public  void arrayByString(int n){
     if(table.getRowCount()==0)
            arrayWarn();
      else{  	
        int row=data.length;
    	Object temp;
    	for(int i=0;i<row-1;i++){
    		for(int j=0;j<row-1;j++){
    	   	 if((String.valueOf(data[j][n]).compareToIgnoreCase
    	   	 		      (String.valueOf(data[j+1][n])))>0){
    	   	   for(int z=0;z<7;z++){
        	 	temp=data[j][z];
        	 	data[j][z]=data[j+1][z];
        	 	data[j+1][z]=temp;
        	   }                            
    	   	 }
    		} 
    	 }	
        updateTable(data); 
      }  
    }
    

    //按学号排序
    public void arrayByStudentId(){
      if(table.getRowCount()==0)
         arrayWarn();
      else{  
        int row=data.length;
    	Object temp;
    	for(int i=0;i<row-1;i++){
    	   for(int j=0;j<row-1;j++){
               String a=String.valueOf(data[j][0]);
    	       String b=String.valueOf(data[j+1][0]);
               int aa,bb;
    	       if(a.equals(""))    
                    a=new String("0");    //如果输入“”,则会产生异常
               if(b.equals(""))    
                    b=new String("0"); 	 
               aa=Integer.parseInt(a);
    	       bb=Integer.parseInt(b);
               if(aa>bb){ 
    	           for(int z=0;z<8;z++){
                       temp=data[j][z];
                       data[j][z]=data[j+1][z];
                       data[j+1][z]=temp;
                   }
               }                            
    	    }
         } 
         updateTable(data);  
       }
    }
 
    //按成绩排序
    public  void arrayByStudentMark(){
      arrayByString(6);
    }
    
    //按课程排序
    public  void arrayByStudentLesson(){    
       arrayByString(5); 
    }
   



 
    //更新列表
    public static void updateList(Vector m){
       for(int i=listRow-1;i>=0;i--)
          listModel.remove(i);
       for(int i=0;i<m.size();i++) 
          listModel.addElement(m.elementAt(i));
       listRow=m.size();
    }
   
    //更新表格
    public static void updateTable(Object[][] d){
       data=d;                            
       for(int i=0;i<m.getRowCount();i++)  //移出当前表中所有元素
    	  while(m.getRowCount()!=0)  
       	    m.removeRow(i); 
       for(int j=0;j<d.length;j++){ 
            m.addRow(d[j]);
            System.out.println("table row:"+m.getRowCount());
       }
    }
 
    //当点击修改按钮时,则产生修改事件
    public void resetMark(){
         if(table.getSelectedRow()==-1){
           MsgDialog dialog=new MsgDialog(this,"请选择一项进行修改");
           LocationSet.setDialogLocation(dialog);
         }
         else{
           MarkFrame mark=
               new MarkFrame(data,table.getSelectedRow()); //修改某系中某学生的成绩  
          LocationSet.setFrameLocation(mark);
         } 
    }
 
   //设置ip
    public void ipsetEvent(){
        new IpsetFrame(this);
    }
     
    public void arrayWarn(){
       new MsgDialog(this,"请先双击系名列表中的项,再进行排序!");
    }
    public static void main(String args[]){
      try{
            UIManager.setLookAndFeel(
                  UIManager.getSystemLookAndFeelClassName());
      }catch(Exception e){}
        new TeacherMainFrame();
    }
    
 }











    
   

⌨️ 快捷键说明

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