www.pudn.com > stundenplan.rar > StundenplanWochenendeModel2.java


/* 
 * StundenplanWochenModel.java 
 * 
 * Created on 26. Mai 2005, 11:03 
 */ 
 
/** 
 * 
 * @author Honger 
 */ 
package stundenplan; 
 
import javax.swing.*; 
import javax.swing.event.*; 
import javax.swing.table.*; 
 
import java.util.*; 
import java.awt.*; 
import java.awt.event.*; 
//import java.awt.print.*;(fuer Version <= 1.3) 
//import javax.print.*;(fuer Version >= 1.4) 
//aber beide hier brauchen nicht, weil mit kb-class 
import kb.tp.KBTablePrinter; 
import kb.param.*; 
 
import java.sql.*; 
 
public class StundenplanWochenendeModel2 extends JFrame implements ActionListener{   
    String sebe = ""; 
    String fach = ""; 
    String raum = ""; 
    String prof = ""; 
    String wochentag = ""; 
    String zeit = ""; 
    String tableName1 = "Alle"; 
    String tableName2 = "Alle"; 
    String tableName3 = "Alle"; 
    String tableName4 = "Alle"; 
    String tableName5 = "Alle"; 
    String tableName6 = "Alle"; 
    int shiZahl = 0; 
    int geZahl = 0; 
    int gesColumnZahl = 9; 
    int gesCowZahl = 8; 
    int tabelleZahl = 3; 
    String[] columnNames = new String[gesColumnZahl];    
    Object[][] data = new Object[gesCowZahl][gesColumnZahl];  
    Fariseme frsm = new Fariseme(); 
    Fach fc = new Fach(); 
    Raum ru = new Raum(); 
    Prof po = new Prof(); 
    TagWochenende2 tawe2 = new TagWochenende2(); 
    ZeitWochenende2 ziwe2 = new ZeitWochenende2(); 
    MyTableModel wochenModel = new MyTableModel(); 
    TableModel model; 
    JTable wochenTable; 
    ResultSet rs; 
 
   //Folgende GUI-Komponente mu?als global Daten difinieren     
    JLabel anweisung = new JLabel(":-)Stundenplan--WochenendeModel2(-:");  
    JLabel label7 = new JLabel(); 
    JComboBox sebeBox = new JComboBox(); 
    JComboBox fachBox = new JComboBox(); 
    JComboBox raumBox = new JComboBox(); 
    JComboBox profBox = new JComboBox(); 
    JComboBox tableNames1 = new JComboBox();  
    JComboBox tableNames2 = new JComboBox();  
    JComboBox tableNames3 = new JComboBox();  
    JComboBox tableNames4 = new JComboBox();  
    JComboBox tableNames5 = new JComboBox();  
    JComboBox tableNames6 = new JComboBox();  
    
   //Die ÜBERTRAGUNGnötige Elemente für Suchmaschine 
   JPanel pa = new JPanel(); 
   int gesamtCow = 0;    
   private JScrollPane scrollPane; 
   private ResultSet r; 
   private ResultSetTableModel mod; 
    
    
    public StundenplanWochenendeModel2() { 
        //super(new BorderLayout()); 
         setTitle(":::STUNDENPLAN---WOCHENENDEMODEL2:::"); 
         setSize(1200, 384); 
         addWindowListener(new WindowAdapter() 
         {  public void windowClosing(WindowEvent e) 
            {       
                System.exit(0); 
            } 
         } ); 
//------------------------------------------------------------------------------------------- 
//---------------------------- Sets up menu entries -----------------------------------------          
        JMenuBar menubar = new JMenuBar(); 
        setJMenuBar(menubar);  
         
        JMenu fileMenu = new JMenu( "File" ); 
        menubar.add(fileMenu); 
     // fileMenu.add( new MenuItemV2( "Show Parameter...", this)); 
        fileMenu.add( new MenuItemV2( "Page Setup...", this )); 
        fileMenu.add( new MenuItemV2( "Print...", this )); 
        fileMenu.addSeparator(); 
        fileMenu.add( new MenuItemV2( "Exit", this )); 
        JMenu viewMenu = new JMenu( "View" ); 
        menubar.add(viewMenu); 
        viewMenu.add( new MenuItemV2( "Week overall view", this)); 
         
        JMenu modelMenu = new JMenu( "Model" ); 
        menubar.add(modelMenu); 
        modelMenu.add( new MenuItemV2( "Weekday", this)); 
        modelMenu.add( new MenuItemV2( "Even weekend", this)); 
        modelMenu.add( new MenuItemV2( "Uneven weekend", this)); 
//-------------------------------------------------------------------------------------------   
     try{  
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select tagwochenende2 from tagwochenende2 order by tagee_id"; 
            ResultSet r = stmt.executeQuery(query);  
            columnNames[0] = ""; 
            int ColumnZahl = 1; 
            while(r.next()){   
            columnNames[ColumnZahl] = (r.getString(1));  
            ColumnZahl++ ;    
                           }             
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
          
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select zeitwochenende2 from zeitwochenende2 order by zeitee_id"; 
            ResultSet r = stmt.executeQuery(query); 
            int CowZahl = 0;  
            while(r.next()){      
           for (int i = 0; i < gesColumnZahl; i++){ 
           if(i == 0) data[CowZahl][i]=(r.getString(1)); 
           if(i != 0) data[CowZahl][i]=""; 
            } 
           CowZahl++;  
           }                           
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
  //----------------------------------------------------------------------------------------        
  //-------------------------------allgemeine GUI-Komponente-------------------------------- 
  //----------------------------------------------------------------------------------------        
  //::: 14 Elemente auf Suchmaschine 
    //7 Label auf Suchmaschine 
    JLabel label1 = new JLabel(); 
    JLabel label2 = new JLabel(); 
    JLabel label3 = new JLabel(); 
    JLabel label4 = new JLabel(); 
    JLabel label5 = new JLabel(); 
    JLabel label6 = new JLabel(); 
    //6 ComboBox auch auf Suchmaschine 
 
    //1 Button auf Suchmaschine  
    JButton such = new JButton("Suchen"); 
    JPanel pq = new JPanel(new GridLayout(1,14)); 
     
  //:::1 Element auf Tip-Bereich 
    JPanel tipPane = new JPanel(new GridLayout(1,1)); 
     
  //:::14 Elemente auf Eingabe-Bereich 
    JButton changeSebe = new JButton("Fari&Seme:"); 
    JButton changeFach = new JButton("Fach:"); 
    JButton changeRaum = new JButton("Raum:"); 
    JButton changeProf = new JButton("Prof:"); 
    JButton changeTagWochenModel = new JButton("Tag:"); 
    JButton changeZeitWochenModel = new JButton("Zeit:"); 
    final JLabel wochentagergLabel = new JLabel(""); 
    final JLabel zeitergLabel = new JLabel(""); 
    JButton ok = new JButton("Speichern"); 
    JButton delete = new JButton("Loeschen"); 
    JPanel eingabeContainer = new JPanel(new GridLayout(7,2)); 
     
  //:::Table-Bereich 
 
 
  //:::Zusammensetzung von obigen TeilContainern 
    JPanel topHalf = new JPanel(); 
    JPanel bottomHalf = new JPanel();  
 
    JPanel tableContainer = new JPanel(new GridLayout(1,1)); 
    JSplitPane ganzPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,topHalf,bottomHalf); 
     
    //wochenModel --> wochenTable 
         wochenTable = new JTable(wochenModel) {   
            public String getToolTipText(MouseEvent e) { 
                String tip = null;             
                java.awt.Point p = e.getPoint(); 
                int rowIndex = rowAtPoint(p); 
                int colIndex = columnAtPoint(p); 
                int realColumnIndex = convertColumnIndexToModel(colIndex); 
 
               if (realColumnIndex != 0) { //Veggie column                  
                shiZahl = rowIndex; 
                geZahl = colIndex;                 
                model = getModel(); 
                zeit = (String)model.getValueAt(rowIndex,0); 
                wochentag = (String)model.getColumnName(colIndex); 
                wochentagergLabel.setText(wochentag); 
                zeitergLabel.setText(zeit); 
                } else {  
                    //You can omit this part if you know you don't  
                    //have any renderers that supply their own tool  
                    //tips. 
                    tip = super.getToolTipText(e); 
                }             
                return tip;   
            } 
        };                 
        wochenTable.setRowHeight(21); 
         
//:::Beschreibung über Eingabe-Bereich  
      changeSebe.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonChSebeActionPerformed(evt); 
          } 
      }); 
      changeFach.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonChFachActionPerformed(evt); 
          } 
      }); 
 
      changeRaum.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonChRaumActionPerformed(evt); 
          } 
      }); 
 
      changeProf.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonChProfActionPerformed(evt); 
          } 
      }); 
 
      changeTagWochenModel.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonChTagWochenModelActionPerformed(evt); 
          } 
      }); 
 
      changeZeitWochenModel.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonChZeitWochenModelActionPerformed(evt); 
          } 
      }); 
 
            sebeBox.addItem(""); 
            //add Fachrichtung und SemesterZahl aus Datenbank 
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select fachrichtungsemester from fariSeme "; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            sebeBox.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
 
            fachBox.addItem(""); 
            //add Fach aus Datenbank 
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select fach from fach"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            fachBox.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
 
            raumBox.addItem(""); 
            //add Raum aus Datenbank 
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select raum from raum"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            raumBox.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
        
            profBox.addItem(""); 
            //add Professor-Item aus Datenbank          
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select name from professor"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            profBox.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
                        
        sebeBox.addActionListener(this); 
        fachBox.addActionListener(this); 
        raumBox.addActionListener(this); 
        profBox.addActionListener(this); 
  
        ok.addActionListener(new java.awt.event.ActionListener() { 
            public void actionPerformed(java.awt.event.ActionEvent evt) { 
                jButtonOkActionPerformed(evt); 
            } 
        });   
 
        delete.addActionListener(new java.awt.event.ActionListener() { 
            public void actionPerformed(java.awt.event.ActionEvent evt) { 
                jButtonDeActionPerformed(evt); 
            } 
        });   
 
 //:::folgende Inhalt beschreibt die Suchmaschine-Bereich   
      //definiert die Elemente ,die auf Suchmaschine liegen       
      label1.setText("Fari&Seme:"); 
      label2.setText("Fach:"); 
      label3.setText("Raum:"); 
      label4.setText("Prof.:"); 
      label5.setText("Tag:"); 
      label6.setText("Zeit:"); 
       
          tableNames1.addItem("Alle");  
          //add Fachrichtung und SemesterZahl aus Datenbank bei der Suchmaschine 
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select fachrichtungsemester from fariSeme "; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            tableNames1.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
          
          tableNames2.addItem("Alle"); 
            //add Fach aus Datenbank bei der Suchmaschine 
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select fach from fach"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            tableNames2.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
      
          tableNames3.addItem("Alle"); 
            //add Raum aus Datenbank bei der Suchmaschine 
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select raum from raum"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            tableNames3.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
 
          tableNames4.addItem("Alle"); 
         //add Professor aus Datenbank bei der Suchmaschine          
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select name from professor"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            tableNames4.addItem(r.getString(1));                    
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
           
          tableNames5.addItem("Alle"); 
         //add Tag aus Datenbank bei der Suchmaschine         
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select tagwochenende2 from tagwochenende2"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){  
            tableNames5.addItem(r.getString(1)); 
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
           
          tableNames6.addItem("Alle"); 
         //add Zeit aus Datenbank bei der Suchmaschine         
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            String query = "select zeitwochenende2 from zeitwochenende2"; 
            ResultSet r = stmt.executeQuery(query);  
            while(r.next()){                           
            tableNames6.addItem(r.getString(1));  
                           } 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         }           
      tableNames1.addActionListener(this); 
      tableNames2.addActionListener(this); 
      tableNames3.addActionListener(this); 
      tableNames4.addActionListener(this); 
      tableNames5.addActionListener(this); 
      tableNames6.addActionListener(this); 
 
      such.addActionListener(new java.awt.event.ActionListener() { 
          public void actionPerformed(java.awt.event.ActionEvent evt) { 
              jButtonSuActionPerformed(evt); 
          } 
      }); 
         
        //Do the layout.        
        eingabeContainer.setBorder(BorderFactory.createTitledBorder("Eingabe")); 
        eingabeContainer.add(changeSebe); 
        eingabeContainer.add(sebeBox); 
        eingabeContainer.add(changeFach); 
        eingabeContainer.add(fachBox); 
        eingabeContainer.add(changeRaum); 
        eingabeContainer.add(raumBox); 
        eingabeContainer.add(changeProf); 
        eingabeContainer.add(profBox); 
        eingabeContainer.add(changeTagWochenModel); 
        eingabeContainer.add(wochentagergLabel); 
        eingabeContainer.add(changeZeitWochenModel); 
        eingabeContainer.add(zeitergLabel); 
        eingabeContainer.add(ok); 
        eingabeContainer.add(delete); 
        //die folgende Zeile sehr wichtig, kann man sie nicht bei Anfang liegen 
        JScrollPane wochenScrollPane = new JScrollPane(wochenTable);  
        tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); 
        tableContainer.add(wochenScrollPane); 
        wochenScrollPane.setPreferredSize(new Dimension(850, 350)); 
         
        topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); 
        topHalf.setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); 
        topHalf.add(eingabeContainer); 
        topHalf.add(tableContainer); 
        topHalf.setPreferredSize(new Dimension(1200, 155));      
                 
        tipPane.setBorder(BorderFactory.createTitledBorder("Tipp")); 
        tipPane.add(anweisung); 
 
      //  pq.setBorder(BorderFactory.createTitledBorder("Suchmaschine")); 
        pq.add(label1); 
        pq.add(tableNames1); 
        pq.add(label2); 
        pq.add(tableNames2); 
        pq.add(label3); 
        pq.add(tableNames3);       
        pq.add(label4); 
        pq.add(tableNames4);  
        pq.add(label5); 
        pq.add(tableNames5);  
        pq.add(label6); 
        pq.add(tableNames6);  
        pq.add(label7); 
        pq.add(such); 
         
        bottomHalf.setLayout(new BoxLayout(bottomHalf, BoxLayout.Y_AXIS)); 
        bottomHalf.setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); 
        bottomHalf.add(tipPane); 
        bottomHalf.add(pq); 
        bottomHalf.setPreferredSize(new Dimension(1024, 150));   
        getContentPane().add(ganzPane, "Center"); 
    } 
     
        //actionPerformed 
    public void jButtonOkActionPerformed(ActionEvent evt){ 
     if(sebe.equals("")||fach.equals("")||raum.equals("")||prof.equals("")){ 
        anweisung.setText("Kontrollieren Sie das Eingabe-Kaestchen, wobei keine leere ComboBox bleiben darf!");  
     } 
     else if(wochentag.equals("")||zeit.equals("")){ 
        anweisung.setText("Die Zeit und Wochentag muessen zuerst gewaelt werden! Bewegen Sie die Mouse auf die Tabelle, koennen Sie die Zeit gewinnen!");  
     } 
     else 
     {    
         String shiZahlStr = String.valueOf(shiZahl); 
         String geZahlStr = String.valueOf(geZahl); 
       try{ 
            Class.forName("org.gjt.mm.mysql.Driver"); 
            Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
            Statement s=c.createStatement(); 
            //Kontrollieren ob die Situation, die widersprüchig sind, wenn ja ,wird gesperrt. 
            //3 Situation: 1.Situation--2 Prof in einem Zeitpunkt 
            //2.Situation--2 Fächer in einem Raum 
            //3.Situation--2 Gruppen Studenten in einem Zeitpunkt haben 2 Fächer, z.B. Vb5 gibt es bei 2 Tabelle die Vorlesung 
            //folgende ist 1.Sperrungsmöglichkeit 
            String sperr1 = "select Studiengang, Fach, Raum, Wochentag, Zeit, shiZahlStr, geZahlStr from stundenplan where Professor = '"+prof+"' and Wochentag = '"+wochentag+"' and Zeit = '"+zeit+"'"; 
            if (rs != null) rs.close(); 
            rs = s.executeQuery(sperr1); 
            int sperri1 = 1; 
            String sone3=""; 
            String sone1=""; 
            String sone2=""; 
              while(rs.next()){      
            sperri1 = sperri1*obSperr(rs.getString(6),rs.getString(7),shiZahlStr,geZahlStr); 
            sone3 = rs.getString(3); 
            sone1 = rs.getString(1); 
            sone2 = rs.getString(2); 
                            } 
            if(sperri1==0){ 
              anweisung.setText(":::PROFESSOR-ZEIT-SPERRUNG:::Bei diesem Zeitpunkt "+wochentag+" "+zeit+" muss Professor/In "+prof+" in Raum "+sone3+" der Gruppe "+sone1+" das Fach "+sone2+" beibringen!");                                
            }             
            //2.Sperrungsmöglichkeit 
                  else{    
                          String sperr2 = "select Studiengang, Fach, Professor, Wochentag, Zeit, shiZahlStr, geZahlStr from stundenplan where Raum = '"+raum+"' and Wochentag = '"+wochentag+"' and Zeit = '"+zeit+"'"; 
                          if (rs != null) rs.close(); 
                          rs = s.executeQuery(sperr2); 
                          int sperri2 = 1; 
                          String stwo3=""; 
                          String stwo1=""; 
                          String stwo2=""; 
                          while(rs.next()){       
                          sperri2 = sperri2*obSperr(rs.getString(6),rs.getString(7),shiZahlStr,geZahlStr);   
                          stwo3 = rs.getString(3); 
                          stwo1 = rs.getString(1); 
                          stwo2 = rs.getString(2); 
                            } 
                          if(sperri2==0){ 
                          anweisung.setText(":::RAUM-ZEIT-SPERRUNG:::Bei diesem Zeitpunkt "+wochentag+" "+zeit+" wird der Raum "+raum+" schon von der Professor/In "+stwo3+" fuer die Vorlesung "+stwo2+" von "+stwo1+" bestellt!");                                
                          }             
                                       //3.Sperrungsmöglichkeit 
                                       else{ 
                                         String sperr3 = "select Fach, Raum, Professor, Wochentag, Zeit, shiZahlStr, geZahlStr from stundenplan where Studiengang = '"+sebe+"' and Wochentag = '"+wochentag+"' and Zeit = '"+zeit+"'"; 
                                         if (rs != null) rs.close(); 
                                         rs = s.executeQuery(sperr3); 
                                         int sperri3 = 1; 
                                         String sthree3=""; 
                                         String sthree1=""; 
                                         String sthree2=""; 
                                         while(rs.next()){       
                                         sperri3 = sperri3*obSperr(rs.getString(6),rs.getString(7),shiZahlStr,geZahlStr);   
                                         sthree3 = rs.getString(3); 
                                         sthree1 = rs.getString(1); 
                                         sthree2 = rs.getString(2); 
                                                         } 
                                         if(sperri3==0){ 
                                         anweisung.setText(":::STUDENT-ZEIT-SPERRUNG:::Die Studenten von Gruppe "+sebe+" haben im Zeitraum "+wochentag+" "+zeit+" schon mit Prof. "+sthree3+" im Raum "+sthree2+" fuer die Vorlesung "+sthree1+" einen Termin!"); 
                                         } 
                                                        else{                 
                                                           String sql="insert into stundenplan(Studiengang,Fach,Raum,Professor,Wochentag,Zeit,shiZahlStr,geZahlStr,tabelleZahl)value('"+sebe+"','"+fach+"','"+raum+"','"+prof+"','"+wochentag+"','"+zeit+"','"+shiZahlStr+"','"+geZahlStr+"',"+tabelleZahl+")"; 
                                                           int done = s.executeUpdate(sql); 
                                                           model.setValueAt(new String(fach+"  "+raum+"  "+prof),shiZahl,geZahl); 
                                                           anweisung.setText("Eine Stunde ( Studiengang "+sebe+"  Fach "+fach+"  Raum "+raum+"  Professor "+prof+"  Wochentag "+wochentag+"  Zeit "+zeit+" ) werden in die Datenbank gespeichert!");            
                                                            } 
                                   } 
                      } 
             
          } 
        catch(Exception ex){ 
            //Problem bei Datenverbindung  
            anweisung.setText("Fehler: "+ex); 
        }  
     } 
    } 
     
   public void jButtonDeActionPerformed(ActionEvent evt){ 
        //anweisung.setText("Wählen Sie eine erwünschte Stunde, die Sie löschen wollen. Dabei sind Fari&Seme, Wochentag und Zeit sehr wichtig!"); 
        if(sebe.equals("")||wochentag.equals("")||zeit.equals("")){ 
        anweisung.setText("Kontrollieren Sie das Eingabe-Kaestchen, wobei Fari&Seme, Wochentag und Zeit nicht leer bleiben duerfen! Bewegen Sie die Mouse auf die Tabelle, koennen Sie die Zeit gewinnen!");  
     } 
     else 
     {    
         String shiZahlStr = String.valueOf(shiZahl); 
         String geZahlStr = String.valueOf(geZahl); 
       try{ 
            Class.forName("org.gjt.mm.mysql.Driver"); 
            Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
            Statement s=c.createStatement(); 
            String sql="DELETE from stundenplan where Studiengang='"+sebe+"' and shiZahlStr='"+shiZahl+"' and geZahlStr='"+geZahl+"' and tabelleZahl="+tabelleZahl; 
            int done = s.executeUpdate(sql); 
            if (done == 0) anweisung.setText("0 row wird geloescht, weil diese Stunde Fachritung&Semester "+sebe+" Wochentag "+wochentag+" Zeit "+zeit+" ) ueberhaupt nicht in der Datenbank existiert!"); 
            else if(done == 1) 
            {model.setValueAt("",shiZahl,geZahl); 
            anweisung.setText("1 row wird geloescht, Diese Stunde ( Fachritung&Semester "+sebe+" Wochentag "+wochentag+" Zeit "+zeit+" ) werden aus der Datenbank geloescht!"); 
            } 
            //folgender Fach ist eigentlich unmöglcih 
            else 
            {model.setValueAt("",shiZahl,geZahl); 
            anweisung.setText("mehr rows werden geloescht"); 
            } 
        } 
        catch(Exception ex){ 
            //Hier kann man nicht ausschliessen, dass es bei Datenverbindung Problem gibt   
            anweisung.setText("Kontrollieren Sie bitte noch mal, ob diese Stunde in der Datenbank existiert!");  
            System.out.println("Fehler: "+ex); 
        }           
     }    
  }   
 
   public void jButtonChSebeActionPerformed(ActionEvent evt){ 
        //Schedule a job for the event-dispatching thread: 
        //creating and showing this application's GUI. 
        javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                frsm.createAndShowGUI(); 
            } 
        });  
  } 
   
   public void jButtonChFachActionPerformed(ActionEvent evt){ 
        //Schedule a job for the event-dispatching thread: 
        //creating and showing this application's GUI. 
        javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                fc.createAndShowGUI(); 
            } 
        });      
  } 
   
   public void jButtonChRaumActionPerformed(ActionEvent evt){ 
        //Schedule a job for the event-dispatching thread: 
        //creating and showing this application's GUI. 
        javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                ru.createAndShowGUI(); 
            } 
        });          
  } 
     
   public void jButtonChProfActionPerformed(ActionEvent evt){ 
        //Schedule a job for the event-dispatching thread: 
        //creating and showing this application's GUI. 
        javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                po.createAndShowGUI(); 
            } 
        });          
  } 
    
   public void jButtonChTagWochenModelActionPerformed(ActionEvent evt){ 
        //Schedule a job for the event-dispatching thread: 
        //creating and showing this application's GUI. 
        javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                tawe2.createAndShowGUI(); 
            } 
        });       
  } 
      
   public void jButtonChZeitWochenModelActionPerformed(ActionEvent evt){ 
        //Schedule a job for the event-dispatching thread: 
        //creating and showing this application's GUI. 
        javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() { 
                ziwe2.createAndShowGUI(); 
            } 
        });  
  } 
         
    public int obLeer(String ein){ 
        int i; 
       if((ein.compareTo("")) == 0){ 
           i = 0; 
       }      
       else i = 1; 
       return i;  
    } 
  
   public int obSperr(String ein1, String ein2, String ein3, String ein4){ 
        int i; 
       if((ein1.compareTo(ein3))==0 && (ein2.compareTo(ein4))==0) 
           i = 0; 
       else i = 1; 
        return i; 
   } 
    
   private void jButtonSuActionPerformed(ActionEvent evt) {       
        
         try{ 
         Class.forName("org.gjt.mm.mysql.Driver"); 
         Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
         Statement stmt=c.createStatement();  
            if (rs != null) rs.close();  
            if(tableName1.equals("Alle"))  tableName1="is not null"; 
            else tableName1 = ("= '" + tableName1 + "'"); 
            if(tableName2.equals("Alle"))  tableName2="is not null"; 
            else tableName2 = ("= '" + tableName2 + "'"); 
            if(tableName3.equals("Alle"))  tableName3="is not null"; 
            else tableName3 = ("= '" + tableName3 + "'"); 
            if(tableName4.equals("Alle"))  tableName4="is not null"; 
            else tableName4 = ("= '" + tableName4 + "'"); 
            if(tableName5.equals("Alle"))  tableName5="is not null"; 
            else tableName5 = ("= '" + tableName5 + "'"); 
            if(tableName6.equals("Alle"))  tableName6="is not null"; 
            else tableName6 = ("= '" + tableName6 + "'"); 
            String query = "select Studiengang, Fach, Raum, Professor, Wochentag, Zeit from stundenplan where Studiengang "+tableName1+" and Fach "+tableName2+" and Raum "+tableName3+" and Professor "+tableName4+" and Wochentag "+tableName5+" and Zeit "+tableName6+" order by Studiengang,Zeit,Fach"; 
            ResultSet r = stmt.executeQuery(query);  
            gesamtCow = 0; 
            while(r.next()){                           
            gesamtCow++;                     
                            } 
            label7.setText(String.valueOf(gesamtCow)+" gefunden."); 
            mod = new ScrollingResultSetTableModel(r);             
            JTable table = new JTable(mod); 
            scrollPane = new JScrollPane(table); 
            getContentPane().add(scrollPane,"South"); 
            pack();             
            doLayout(); 
            anweisung.setText("Die Suchergebnisse sind schon in der folgenden Tabelle!"); 
         } 
         catch(Exception e) 
         {  anweisung.setText("Fehler: "+e);   
         } 
        
   } 
   
    public void close(ResultSet rs){        
        if(rs !=null){ 
            try{ 
               rs.close(); 
            } 
            catch(Exception e){}       
        } 
    } 
   /* Diese Klasse ist die Basisklasse der Tabellenmodelle f? 
   bildlauff?ige und manuell zwischengespeicherte Ergebnismengen. 
   Sie speichert die Ergebnismenge und ihre Metadaten. 
*/ 
 
abstract class ResultSetTableModel extends AbstractTableModel 
{  public ResultSetTableModel(ResultSet aResultSet) 
   {  rs = aResultSet; 
      try 
      {  rsmd = rs.getMetaData(); 
      } 
      catch(SQLException e) 
      {  System.out.println("Fehler " + e);   
      } 
   } 
 
   public String getColumnName(int c) 
   {  try 
      {  return rsmd.getColumnName(c + 1); 
      } 
      catch(SQLException e) 
      {  System.out.println("Fehler " + e);   
         return ""; 
      } 
   } 
 
   public int getColumnCount()  
   {  try 
      {  return rsmd.getColumnCount();  
      } 
      catch(SQLException e) 
      {  System.out.println("Fehler " + e);   
         return 0; 
      } 
   } 
    
   protected ResultSet getResultSet() 
   {  return rs; 
   } 
    
   private ResultSet r; 
   private ResultSetMetaData rsmd; 
} 
 
/* Diese Klasse verwendet einen bildlauff?igen Cursor, 
   ein JDBC 2-Feature 
*/ 
 
class ScrollingResultSetTableModel extends ResultSetTableModel  
{  public ScrollingResultSetTableModel(ResultSet aResultSet) 
   {  super(aResultSet); 
   } 
 
   public Object getValueAt(int r, int c) 
   {  try 
      {  ResultSet rs = getResultSet(); 
         rs.absolute(r + 1); 
         return rs.getObject(c + 1); 
      } 
      catch(SQLException e) 
      {  System.out.println("Fehler " + e);   
         return null; 
      } 
   } 
    
   public int getRowCount() 
   {  try 
      {  ResultSet rs = getResultSet(); 
         rs.last(); 
         return rs.getRow(); 
      } 
      catch(SQLException e) 
      {  System.out.println("Fehler " + e);   
         return 0; 
      } 
   } 
} 
 
  class MyTableModel extends AbstractTableModel { 
        
        public int getColumnCount() { 
            return columnNames.length; 
        } 
 
        public int getRowCount() { 
            return data.length; 
        } 
 
        public String getColumnName(int col) { 
            return columnNames[col]; 
        } 
 
        public Object getValueAt(int row, int col) { 
            return data[row][col]; 
        } 
        /* 
         * Don't need to implement this method unless your table's 
         * editable. 
         */ 
        public boolean isCellEditable(int row, int col) { 
            //Note that the data/cell address is constant, 
            //no matter where the cell appears onscreen. 
            if (col < 2) { 
                return false; 
            } else { 
                return true; 
            } 
        } 
        public void setValueAt(Object value, int row, int col) { 
            boolean DEBUG = false; 
            if (DEBUG) { 
                System.out.println("Setting value at " + row + "," + col 
                                   + " to " + value 
                                   + " (an instance of " 
                                   + value.getClass() + ")"); 
            } 
 
            data[row][col] = value; 
            fireTableCellUpdated(row, col); 
 
            if (DEBUG) { 
                System.out.println("New value of data:"); 
                printDebugData(); 
            } 
        } 
 
        private void printDebugData() { 
            int numRows = getRowCount(); 
            int numCols = getColumnCount(); 
 
            for (int i=0; i < numRows; i++) { 
                System.out.print("    row " + i + ":"); 
                for (int j=0; j < numCols; j++) { 
                    System.out.print("  " + data[i][j]); 
                } 
                System.out.println(); 
            } 
            System.out.println("--------------------------"); 
        } 
    } 
   
    /// ActionListener interface function 
    /// Responds to JMenuItem, JTextField and JButton actions 
 public void actionPerformed(ActionEvent e)  
   {  if (e.getSource() == sebeBox) 
           sebe = (String)sebeBox.getSelectedItem();  
      if (e.getSource() == fachBox) 
           fach = (String)fachBox.getSelectedItem();    
      if (e.getSource() == raumBox) 
           raum = (String)raumBox.getSelectedItem();  
      if (e.getSource() == profBox) 
           prof = (String)profBox.getSelectedItem();  
      //Oberline---------------------------------------------------- 
         if (scrollPane != null)  
         getContentPane().remove(scrollPane); 
           tableName1 = (String)tableNames1.getSelectedItem(); 
           tableName2 = (String)tableNames2.getSelectedItem();   
           tableName3 = (String)tableNames3.getSelectedItem();      
           tableName4 = (String)tableNames4.getSelectedItem(); 
           tableName5 = (String)tableNames5.getSelectedItem();           
           tableName6 = (String)tableNames6.getSelectedItem(); 
      //Unterline-------------------------------------------------- 
    /// ActionListener interface function 
    /// Responds to JMenuItem, JTextField and JButton actions 
        Object source = e.getSource(); 
 
 if ( source instanceof JMenuItem ) { 
            JMenuItem mi = (JMenuItem) source; 
            String itemName = mi.getLabel(); 
// if ( itemName.equals( "Show Parameter..." )) 
    //  {  
    // KBTablePrinter.showParamFrame(columnNames, data, FormatGeneral.getDefaultSettings(null), true, true, true); 
    //  } 
   if ( itemName.equals( "Page Setup..." )) 
      {  
     KBTablePrinter.showPreviewFrame(columnNames, data, FormatGeneral.getDefaultSettings(null), true, true, true);              
      } 
   else if ( itemName.equals( "Print..." )) 
       {   
     KBTablePrinter.print(columnNames, data, FormatGeneral.getDefaultSettings(null), true, true, true, false); 
       } 
   else if ( itemName.equals( "Exit" )) 
              System.exit(0); 
   else if ( itemName.equals( "Week overall view" )) 
    if((obLeer(sebe) + obLeer(fach) + obLeer(raum) + obLeer(prof)) == 1){ 
   
           if(obLeer(sebe) == 1){   
            try{Class.forName("org.gjt.mm.mysql.Driver"); 
             Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
             Statement s=c.createStatement();   
             String sql = "select Fach, Raum, Professor, shiZahlStr, geZahlStr from stundenplan where Studiengang = '"+sebe+"' and tabelleZahl = "+tabelleZahl; 
             if (rs != null) rs.close(); 
             rs = s.executeQuery(sql);              
             ResultSetMetaData rm =rs.getMetaData(); 
             for (int i = 0; i < model.getRowCount(); i++) 
                 for (int j = 1; j < model.getColumnCount(); j++) 
                     model.setValueAt(new String(""), i, j); 
             while(rs.next()){       
             model.setValueAt(new String(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3)),Integer.valueOf(rs.getString(4)).intValue(),Integer.valueOf(rs.getString(5)).intValue());                            
                            } 
             anweisung.setText("Die Tabelle vom Fachbereich "+sebe+" ist schon da!"); 
                 }  
            catch(Exception ex){ 
            anweisung.setText("Beruehren Sie Ihre Mouse einmal auf diese Tabelle bis den Zeitpunkt, wobei Wochentag und Zeit im Eingabe-Kaestchen auftritt, um das neue Modell zu initiieren!"); 
                              } 
           } 
               
           else if(obLeer(fach) == 1){ 
             try{Class.forName("org.gjt.mm.mysql.Driver"); 
             Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
             Statement s=c.createStatement();     
             String sql = "select Studiengang, Raum, Professor, shiZahlStr, geZahlStr from stundenplan where Fach = '"+fach+"' and tabelleZahl = "+tabelleZahl; 
             if (rs != null) rs.close(); 
             rs = s.executeQuery(sql); 
             ResultSetMetaData rm =rs.getMetaData(); 
             for (int i = 0; i < model.getRowCount(); i++) 
                 for (int j = 1; j < model.getColumnCount(); j++) 
                     model.setValueAt(new String(""), i, j); 
             while(rs.next()){                           
             model.setValueAt(new String(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3)),Integer.valueOf(rs.getString(4)).intValue(),Integer.valueOf(rs.getString(5)).intValue());                            
                            } 
             anweisung.setText("Die Tabelle vom Fach "+fach+" ist schon da!"); 
             }          
             catch(Exception ex){ 
             anweisung.setText("Beruehren Sie Ihre Mouse einmal auf diese Tabelle bis den Zeitpunkt, wobei Wochentag und Zeit im Eingabe-Kaestchen auftritt, um das neue Modell zu initiieren!"); 
                              }            
                } 
            
           else if(obLeer(raum) == 1){ 
             try{Class.forName("org.gjt.mm.mysql.Driver"); 
             Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
             Statement s=c.createStatement(); 
             String sql = "select Fach, Studiengang, Professor, shiZahlStr, geZahlStr from stundenplan where Raum = '"+raum+"' and tabelleZahl = "+tabelleZahl; 
             if (rs != null) rs.close(); 
             rs = s.executeQuery(sql); 
             ResultSetMetaData rm =rs.getMetaData(); 
             for (int i = 0; i < model.getRowCount(); i++) 
                 for (int j = 1; j < model.getColumnCount(); j++) 
                     model.setValueAt(new String(""), i, j); 
             while(rs.next()){                           
             model.setValueAt(new String(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3)),Integer.valueOf(rs.getString(4)).intValue(),Integer.valueOf(rs.getString(5)).intValue());                            
                            } 
             anweisung.setText("Die Tabelle vom Raum "+raum+" ist schon da!"); 
            } 
             catch(Exception ex){ 
             anweisung.setText("Beruehren Sie Ihre Mouse einmal auf diese Tabelle bis den Zeitpunkt, wobei Wochentag und Zeit im Eingabe-Kaestchen auftritt, um das neue Modell zu initiieren!"); 
                              }   
           }             
           else if(obLeer(prof) == 1){ 
             try{Class.forName("org.gjt.mm.mysql.Driver"); 
             Connection c=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","db_pw"); 
             Statement s=c.createStatement();  
             String sql = "select Fach, Raum, Studiengang, shiZahlStr, geZahlStr from stundenplan where Professor = '"+prof+"' and tabelleZahl = "+tabelleZahl;   
             if (rs != null) rs.close(); 
             rs = s.executeQuery(sql); 
             ResultSetMetaData rm =rs.getMetaData(); 
             for (int i = 0; i < model.getRowCount(); i++) 
                 for (int j = 1; j < model.getColumnCount(); j++) 
                     model.setValueAt(new String(""), i, j); 
             while(rs.next()){                           
             model.setValueAt(new String(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3)),Integer.valueOf(rs.getString(4)).intValue(),Integer.valueOf(rs.getString(5)).intValue());                            
                            } 
             anweisung.setText("Die Tabelle vom Professor/In "+prof+" ist schon da!"); 
                 } 
             catch(Exception ex){ 
             anweisung.setText("Beruehren Sie Ihre Mouse einmal auf diese Tabelle bis den Zeitpunkt, wobei Wochentag und Zeit im Eingabe-Kaestchen auftritt, um das neue Modell zu initiieren!"); 
                              } 
                }           
             else  { 
             //folgener Fall ist unmöglich   
             anweisung.setText("Dieser Fall ist unmoeglich!"); 
             } 
        } 
    
    else{ 
             anweisung.setText("Kontrollieren Sie das Eingabe-Kaestchen, wobei genau ein ComboBox ausser Wochentag und Zeit noch gewaelt werden muss"); 
        } 
   else if ( itemName.equals( "Weekday" )) 
     { 
      JFrame frame = new StundenplanWochenModel(); 
      frame.show();            
     } 
   else if ( itemName.equals( "Even weekend" )) 
     { 
      JFrame frame = new StundenplanWochenendeModel1(); 
      frame.show();            
     } 
   else if ( itemName.equals( "Uneven weekend" )) 
     { 
      JFrame frame = new StundenplanWochenendeModel2(); 
      frame.show();            
     } 
   } 
 } 
  
    private final class MenuItemV2 extends JMenuItem { 
        public MenuItemV2( String name, ActionListener al ) { 
            super( name ); 
            this.addActionListener( al ); 
        } 
    } 
       
}