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


import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
 
import java.util.*; 
import java.sql.*; 
 
 
 
 
public class DisposePane extends JPanel implements ActionListener,ItemListener{ 
	JComboBox cb1=new JComboBox(); 
	TextArea ta=new TextArea("",500,500,10); 
	JTextField tf[]=new JTextField[5]; 
	JButton b1=new JButton("关闭提交功能"); 
	JButton b4=new JButton("开启提交功能"); 
	JButton b2=new JButton("确定"); 
 
	 
	String s[]=new String[6]; 
	 
	////////// 
	String sql;  
    Connection conn;  
    Statement stmt;  
    ResultSet rs; 
	 
	DisposePane(){ 
		JLabel l1=new JLabel("布置作业"); 
		JLabel l2=new JLabel("选择话题"); 
		JLabel l3=new JLabel("输入每个阶段提交期限(YYYY-MM-DD)"); 
		JLabel l4=new JLabel("第一阶段"); 
		JLabel l5=new JLabel("第二阶段"); 
		JLabel l6=new JLabel("第三阶段"); 
		JLabel l7=new JLabel("第四阶段"); 
		JLabel l8=new JLabel("第五阶段"); 
		add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);add(l7);add(l8); 
		add(cb1);add(ta);add(b1);add(b2);add(b4); 
		for(int i=0;i<5;i++){ 
			tf[i]=new JTextField(13); 
			add(tf[i]); 
		} 
		String s[]={"first","second","third","fouth","fifth"}; 
		for(int i=0;i<3;i++){ 
			cb1.addItem(s[i]); 
		} 
		//////// 
		this.setLayout(null); 
		this.setBackground(Color.orange); 
		l1.setBounds(200, 20, 150, 30); 
		l2.setBounds(60, 60, 100, 40); 
		cb1.setBounds(130, 70, 150, 20); 
		l3.setBounds(5, 90, 150, 20); 
		l4.setBounds(10, 120, 150, 20); 
		tf[0].setBounds(10, 150, 80, 20); 
		l5.setBounds(10, 180, 150, 20); 
		tf[1].setBounds(10, 210, 80, 20); 
		l6.setBounds(10, 240, 150, 20); 
		tf[2].setBounds(10, 270, 80, 20); 
		l7.setBounds(10, 300, 150, 20); 
		tf[3].setBounds(10, 330, 80, 20); 
		l8.setBounds(10, 370, 150, 20); 
		tf[4].setBounds(10, 400, 80, 20); 
		ta.setBounds(100, 130, 350, 350); 
		b2.setBounds(50, 530, 100, 50); 
 
		b1.setBounds(270, 530, 100, 50); 
		b4.setBounds(380, 530,100,51); 
		///////// 
		init(); 
		cb1.addItemListener(this); 
		b1.addActionListener(this); 
		b2.addActionListener(this); 
 
		b4.addActionListener(this); 
		 
		 
		 
		 
	} 
public void init(){ 
	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(); 
		ta.setText(rs.getString(4).toString().trim()); 
		tf[0].setText(rs.getString(7).substring(0, 10)); 
		tf[1].setText(rs.getString(8).substring(0, 10)); 
		tf[2].setText(rs.getString(9).substring(0, 10)); 
		tf[3].setText(rs.getString(10).substring(0, 10)); 
		tf[4].setText(rs.getString(11).substring(0, 10)); 
		conn.close(); 
		stmt.close();		 
       }catch(Exception e1){JOptionPane.showMessageDialog(null,e1.getMessage());} 
 
} 
	 
	 
	 
	public void actionPerformed(ActionEvent e){ 
		if(e.getSource()==b1){ 
			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="update Teacher set SYSOPEN='0'"; 
				if(stmt.executeUpdate(sql)==1){JOptionPane.showMessageDialog(null, "系统关闭了");} 
				else JOptionPane.showMessageDialog(null, "关闭失败"); 
			}catch(Exception e3){JOptionPane.showMessageDialog(null, e3.getMessage());} 
		} 
		if(e.getSource()==b4){ 
			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="update Teacher set SYSOPEN='1'"; 
				if(stmt.executeUpdate(sql)==1){JOptionPane.showMessageDialog(null, "系统开启了");} 
				else JOptionPane.showMessageDialog(null, "开启失败"); 
			}catch(Exception e4){JOptionPane.showMessageDialog(null, e4.getMessage());} 
		} 
		if(e.getSource()==b2){ 
		try{ 
			int i=cb1.getSelectedIndex(); 
			i=i+1; 
			s[0]=ta.getText().trim(); 
			s[1]=tf[0].getText().trim(); 
			s[2]=tf[1].getText().trim(); 
			s[3]=tf[2].getText().trim(); 
			s[4]=tf[3].getText().trim(); 
			s[5]=tf[4].getText().trim();	 
				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="update Teacher set TOPIC"+i+"='"+s[0]+"',DA1='"+s[1]; 
			    sql=sql+"',DA2='"+s[2]+"',DA3='"+s[3]+"',DA4='"+s[4]+"',DA5='"+s[5]+"'"; 
			    int ok=stmt.executeUpdate(sql); 
			    if(ok==1){JOptionPane.showMessageDialog(null, "保存成功");} 
			    else{JOptionPane.showMessageDialog(null, "保存失败");} 
			    stmt.close(); 
			    conn.close(); 
		}catch(Exception e3){JOptionPane.showMessageDialog(null,e3.getMessage());} 
	} 
	} 
	 
	public void itemStateChanged(ItemEvent 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(); 
			int tem=cb1.getSelectedIndex(); 
			ta.setText(rs.getString(tem+4)); 
	}catch(Exception e2){JOptionPane.showMessageDialog(null,e2.getMessage());} 
	 
	 
	} 
	 
	 
}