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


import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import java.util.*; 
import java.sql.*; 
 
public class StudentFrame extends JFrame implements ActionListener 
{ 
    JButton b0,b1,b2,b3,b4; 
    JPanel ForToolBar=new JPanel(new FlowLayout()); 
    JPanel CenterPane=new JPanel(); 
    CardLayout cl=new CardLayout(); 
 
     
     
///////////////////////// 
    String sql;  
    Connection conn;  
    Statement stmt;  
    ResultSet rs;  
    ///////////// 
    boolean syOpen; 
    String IDtem=new String(); 
    public StudentFrame(String ID) 
    { 
    	IDtem=ID; 
        /////////////ToolBar面板 
        getContentPane().setLayout(new BorderLayout()); 
        JToolBar Mytb=createToolBar(); 
        ForToolBar.add(Mytb); 
        getContentPane().add(ForToolBar,"South"); 
        ////////////////////////中心面板 
        getContentPane().add(CenterPane,"Center"); 
         
        CenterPane.setLayout(cl); 
         
        JPanel p0=new JPanel(); 
        p0.add(new JLabel(new ImageIcon("首页1.JPG"))); 
         
        CenterPane.add(p0,"FirstPage"); 
        CenterPane.add(new ChangeIfon(ID),"ChangeIfon"); 
        CenterPane.add(new LookHomeWork(ID),"LookHomeWork"); 
        CenterPane.add(new SumitHomeWork(ID),"SumitHomeWork"); 
         
        ///////////// 
        setSize(500,800); 
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
        Dimension screen=Toolkit.getDefaultToolkit().getScreenSize(); 
        setLocation((screen.width-500)/2,(screen.height-800)/2); 
        setTitle("welcome to MPX"); 
        setVisible(true); 
    } 
    public JToolBar createToolBar(){ 
        JToolBar tb=new JToolBar(); 
        b0=new JButton("首页",new ImageIcon("1.gif")); 
        b0.setHorizontalTextPosition(AbstractButton.CENTER); 
        b0.setVerticalTextPosition(AbstractButton.BOTTOM); 
        b0.setFocusPainted(false); 
        b0.setRequestFocusEnabled(false); 
         
        b1=new JButton("个人信息管理",new ImageIcon("2.gif")); 
        b1.setHorizontalTextPosition(AbstractButton.CENTER); 
        b1.setVerticalTextPosition(AbstractButton.BOTTOM); 
        b1.setToolTipText("可以查看或修改个人信息"); 
        b1.setFocusPainted(false); 
        b1.setRequestFocusEnabled(false); 
         
        b2=new JButton("查看作业",new ImageIcon("3.gif")); 
        b2.setHorizontalTextPosition(AbstractButton.CENTER); 
        b2.setVerticalTextPosition(AbstractButton.BOTTOM); 
        b2.setToolTipText("可以查看老师布置的作业"); 
        b2.setFocusPainted(false); 
        b2.setRequestFocusEnabled(false); 
         
        b3=new JButton("提交作业",new ImageIcon("4.gif")); 
        b3.setHorizontalTextPosition(AbstractButton.CENTER); 
        b3.setVerticalTextPosition(AbstractButton.BOTTOM); 
        b3.setToolTipText("提交或修改作业"); 
        b3.setFocusPainted(false); 
        b3.setRequestFocusEnabled(false); 
         
        b4=new JButton("退出系统",new ImageIcon("5.gif")); 
        b4.setHorizontalTextPosition(AbstractButton.CENTER); 
        b4.setVerticalTextPosition(AbstractButton.BOTTOM); 
        b4.setFocusPainted(false); 
        b4.setRequestFocusEnabled(false); 
         
        tb.add(b0);tb.add(b1);tb.add(b2);tb.add(b3);tb.add(b4); 
        b0.addActionListener(this); 
        b1.addActionListener(this); 
        b2.addActionListener(this); 
        b3.addActionListener(this); 
        b4.addActionListener(this); 
 
        tb.setRollover(true); 
        getContentPane().add(tb,"North"); 
        tb.setFloatable(true); 
         
        return tb; 
    } 
 
    public void actionPerformed(ActionEvent e){ 
    	if(e.getSource()==b0){ 
    		cl.show(CenterPane, "FirstPage"); 
    	} 
        if(e.getSource()==b1){ 
          cl.show(CenterPane, "ChangeIfon"); 
        } 
        if(e.getSource()==b2){ 
        	cl.show(CenterPane,"LookHomeWork"); 
        } 
        if(e.getSource()==b3){ 
        	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(); 
    			 
    			if(rs.getString(3).trim().equals("1")){syOpen=true;cl.show(CenterPane,"SumitHomeWork");} 
    			else{syOpen=false;JOptionPane.showMessageDialog(null, "系统已关闭");} 
    			conn.close();	 
    			stmt.close();				 
    	} 
    	catch(Exception e1){JOptionPane.showMessageDialog(null,"fuck"+e1.getMessage());} 
        
        } 
         
        if(e.getSource()==b4){ 
        	int n=JOptionPane.showConfirmDialog(null, "退出系统吗"); 
        	if(n==JOptionPane.YES_OPTION){ 
                 dispose(); 
        		 
        		new LoginDia(); 
        	} 
           
        	else 
        		return; 
        } 
 
     
    } 
}