www.pudn.com > st.rar > LookHomeWork.java


import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
 
import java.util.*; 
import java.sql.*; 
 
public class LookHomeWork extends JPanel implements ItemListener{ 
	String sql;  
    Connection conn;  
    Statement stmt;  
    ResultSet rs; 
    boolean syOpen; 
    int topicAccount; 
    String IDtem=new String(); 
     
	JComboBox cb1=new JComboBox(); 
	TextArea ta1=new TextArea("",6,30,10); 
	JComboBox cb2=new JComboBox(); 
	TextArea ta2=new TextArea("",6,30,10); 
	JTextField tf=new JTextField(3); 
	TextArea ta3=new TextArea("",3,20,10); 
	String tem=new String(); 
	JTextField tf2=new JTextField(13); 
	 
	LookHomeWork(String ID){ 
		IDtem=ID; 
		this.setBackground(Color.magenta); 
		setLayout(null); 
		JLabel l1=new JLabel("话题 "); 
		JLabel l2=new JLabel("阶段 "); 
		JLabel l3=new JLabel("分数 "); 
		JLabel l4=new JLabel("评语 "); 
		JLabel l5=new JLabel("期限 "); 
		///////////////// 
		 
		String num[]={"first","second","third","fouth","fifth"}; 
		int i; 
		for(i=0;i<3;i++){ 
			cb1.addItem(num[i]); 
		} 
		for(i=0;i<5;i++){ 
			cb2.addItem(num[i]); 
		} 
		try{ 
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
			String url="jdbc:odbc:SUMMIT";  
			String user="sa";  
			String password="198662";  
			conn= DriverManager.getConnection(url,user,password); 
			stmt=conn.createStatement();  
			sql="select * from Teacher"; 
			rs=stmt.executeQuery(sql); 
			rs.next(); 
			String hw1=new String(); 
			hw1=rs.getString(4); 
			ta1.setText(""); 
			ta1.setText(hw1);				 
			conn.close(); 
			stmt.close();		 
	}catch(Exception e3){ 
		JOptionPane.showMessageDialog(null,e3.getMessage());} 
	try{ 
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
		String url="jdbc:odbc:SUMMIT";  
		String user="sa";  
		String password="198662";  
		conn= DriverManager.getConnection(url,user,password); 
		stmt=conn.createStatement();  
		sql="select * from HomeWork where SNO='"+ID+"'"; 
		rs=stmt.executeQuery(sql); 
		rs.next(); 
		tem=rs.getString(1); 
		ta2.setText(rs.getString(3)); 
		tf.setText(rs.getString(4)); 
		ta3.setText(rs.getString(5)); 
        rs.close(); 
        sql="select * from Teacher"; 
        rs=stmt.executeQuery(sql); 
        rs.next(); 
        tf2.setText(rs.getString(7).substring(0, 11)); 
        conn.close(); 
        stmt.close(); 
      }catch(Exception e4){JOptionPane.showMessageDialog(null,e4.getMessage());} 
       
        tem="你已选择了话题 "+tem; 
        JLabel topic=new JLabel(tem); 
        ta1.setEnabled(false); 
        ta2.setEnabled(false); 
        tf.setEnabled(false); 
        ta3.setEnabled(false); 
        ta1.setFont(new Font("Times",Font.CENTER_BASELINE,15)); 
        ta2.setFont(new Font("Times",Font.CENTER_BASELINE,15)); 
        ta3.setFont(new Font("Times",Font.CENTER_BASELINE,15)); 
        tf.setFont(new Font("Times",Font.CENTER_BASELINE,15)); 
         
		add(cb1);add(ta1);add(cb2);add(ta2);add(tf);add(ta3);add(tf2);add(l5); 
		add(l1);add(l2);add(l3);add(l4);add(topic); 
		JLabel top=new JLabel("           作业管理           "); 
		top.setFont(new Font("Times",Font.CENTER_BASELINE,30)); 
		add(top); 
		top.setBounds(100, 30, 400, 30); 
		l1.setBounds(20, 100, 60, 30); 
		l2.setBounds(20, 300, 60, 30); 
		l3.setBounds(20, 500, 60, 30); 
		l4.setBounds(20, 540, 60, 30); 
		cb1.setBounds(80, 100, 100, 30); 
		topic.setBounds(200, 105, 150, 20); 
		ta1.setBounds(80, 140, 300, 150); 
		cb2.setBounds(80, 300,100,30); 
		l5.setBounds(200, 300, 100, 30); 
		tf2.setBounds(250, 300, 100, 30); 
		tf2.setEditable(false); 
		 
		 
		ta2.setBounds(80,360,300,150); 
		tf.setBounds(80,520,100,30); 
		ta3.setBounds(80,560,400,50); 
		//////////////// 
		 
		cb1.addItemListener(this); 
		cb2.addItemListener(this); 
		//////// 
	 
		 
	} 
	 
 
	 
	public void itemStateChanged(ItemEvent i){ 
		if(i.getSource()==cb1){ 
			String s=cb1.getSelectedItem().toString().trim(); 
			int j=0; 
			 
			if (s.equals("first"))  
			      j=0; 
			if (s.equals("second"))  
				  j=1; 
			if (s.equals("third"))  
				  j=2; 
			 
		 
			try{ 
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
				String url="jdbc:odbc:SUMMIT";  
				String user="sa";  
				String password="198662";  
				conn= DriverManager.getConnection(url,user,password); 
				stmt=conn.createStatement();  
				sql="select * from Teacher"; 
				rs=stmt.executeQuery(sql); 
				rs.next(); 
				String hw=new String(); 
				hw=rs.getString(j+4); 
				ta1.setText(""); 
				ta1.setText(hw);				 
				conn.close(); 
				stmt.close();		 
		}catch(Exception e2){ 
			JOptionPane.showMessageDialog(null,"ri"+e2.getMessage()); 
		} 
	 
	} 
		if(i.getSource()==cb2){ 
			String s=cb2.getSelectedItem().toString().trim(); 
			int j=0; 
			 
			if (s.equals("first"))  
			      j=0; 
			if (s.equals("second"))  
				  j=3; 
			if (s.equals("third"))  
				  j=6; 
			if (s.equals("fouth"))  
				  j=9; 
			if (s.equals("fifth"))  
				  j=12; 
 
			try{ 
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
				String url="jdbc:odbc:SUMMIT";  
				String user="sa";  
				String password="198662";  
				conn= DriverManager.getConnection(url,user,password); 
				stmt=conn.createStatement();  
				sql="select * from HomeWork where SNO='"+IDtem+"'"; 
				rs=stmt.executeQuery(sql); 
				rs.next(); 
				 
				ta2.setText(rs.getString(3+j)); 
				tf.setText(rs.getString(4+j)); 
				ta3.setText(rs.getString(5+j)); 
				 rs.close(); 
				sql="select * from Teacher"; 
				rs=stmt.executeQuery(sql); 
				rs.next(); 
				tf2.setText(rs.getString(7+j/3).substring(0,11)); 
		        
		        conn.close(); 
		        stmt.close(); 
		      }catch(Exception e5){JOptionPane.showMessageDialog(null,e5.getMessage());} 
		} 
	} 
}