import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;

import java.awt.Dimension;
import java.awt.Color;

import java.util.Vector;

import java.awt.*;
import java.awt.event.*;
//import java.io.*;



// Tabelle mit einer Klasse
// Listener in der Spalte der U-Nummern

public class Tabelle11 extends JFrame {

  final int AnzRows = 40;
  final int AnzCols = 10;
  Object[][] data;

  JTable jTable1;

  public Tabelle11() {
      //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocation(100,100);
    this.setSize(450, 350);
    this.setTitle("Tabelle11");
     createData();
   try  {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
      jTable1 = createTable();
      jTable1.addMouseListener(new java.awt.event.MouseAdapter() {

      public void mouseClicked(MouseEvent e) {
        jTable1_mouseClicked(e);
      }
    });

    this.getContentPane().add(new JScrollPane(jTable1), BorderLayout.CENTER);
  }

  void jTable1_mouseClicked(MouseEvent e) {
    System.out.println("e: "+e);
  }


  // createTable
  public JTable createTable() {
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {
        public int getColumnCount() {
          return AnzCols;
        }
        public int getRowCount() {
           return AnzRows;
        }
        public Object getValueAt(int row, int col) {
          return data[row][col];
        }
          // Header nur mit JScrollPane
        public String getColumnName(int column) {
          return new String( "C:"+Integer.toString(column+1) );
        }

        public Class getColumnClass(int c) {
          return getValueAt(0, c).getClass();
          }

        public boolean isCellEditable(int row, int col) {
          return false; //getColumnClass(col) == String.class;
        }
        public void setValueAt(Object aValue, int row, int column) {
          data[row][column] = aValue;
        }
     };

     JTable table = new JTable(dataModel);

        return table;
  } // createTable


  public void createData() {
        // Create the dummy data (a few rows of names)
   data = new String[ AnzRows][AnzCols];
   for (int r=0; r<AnzRows; r++) {
     for (int c=0; c<AnzCols; c++) {
       data[r][c] = Integer.toString(r*1000+c);
     }
   }
  }


  //Überschreiben, damit das Programm bei Herunterfahren des Systems beendet werden kann
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }


    public static void main(String[] args) {
      Tabelle11 frame = new Tabelle11();
      frame.validate();
      frame.setVisible(true);
      frame.show();
    }


}



