package table;import java.awt.event.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.io.*;import java.util.*;import java.awt.*;import javax.swing.JTable;public class TraceFileViewer extends JFrame implements WindowListener, ActionListener{ public static String rowData[][] = {}; public static JTable table = new JTable(); public static DefaultTableModel model = new DefaultTableModel(); public static JFrame frame = new JFrame("TraceFile-Viewer"); MenuBar Menueleiste=new MenuBar (); public static void main ( String args[] ) { ReadLogfile(); //table.setPreferredSize(new Dimension(800,300)); frame.setSize(1000,500); frame.setResizable(true); frame.getContentPane().add( new JScrollPane(table) ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); //frame.pack(); frame.setVisible( true ); } public TraceFileViewer () { frame.setMenuBar(Menueleiste); MenuBar Menueleiste=new MenuBar (); Menu MenuePunkt1=new Menu ("Datei"); Menu MenuePunkt2=new Menu ("Ansicht"); Menueleiste.add(MenuePunkt1); MenuItem neu=new MenuItem ("Neu"); neu.setShortcut(new MenuShortcut('n')); MenuePunkt1.add(neu); MenuItem laden=new MenuItem ("Laden..."); laden.setShortcut(new MenuShortcut('l')); MenuePunkt1.add(laden); MenuItem speichern=new MenuItem ("Speichern..."); speichern.setShortcut(new MenuShortcut('s')); MenuePunkt1.add(speichern); MenuItem drucken=new MenuItem ("Drucken"); drucken.setShortcut(new MenuShortcut('d')); MenuePunkt1.add(drucken); MenuePunkt1.addSeparator(); MenuItem beenden=new MenuItem ("Beenden"); beenden.setShortcut(new MenuShortcut('q')); MenuePunkt1.add(beenden); add(frame); setVisible(true); Menueleiste.add(MenuePunkt2); setMenuBar(Menueleiste); addWindowListener(this); neu.addActionListener(this); laden.addActionListener(this); speichern.addActionListener(this); drucken.addActionListener(this); beenden.addActionListener(this); // if (parameter.length!=0) // { // dateiname=parameter[0]; // DateiLaden(dateiname); // } } public void actionPerformed (ActionEvent evt) { if (evt.getSource() instanceof MenuItem) { String eintrag=evt.getActionCommand(); if (eintrag.equals("Beenden")) { dispose(); System.exit(0); } } } public void windowClosing(WindowEvent evt) { dispose(); System.exit(0); } public void windowOpened(WindowEvent evt) {} public void windowIconified(WindowEvent evt) {} public void windowDeiconified(WindowEvent evt) {} public void windowClosed(WindowEvent evt) {} public void windowActivated(WindowEvent evt) {} public void windowDeactivated(WindowEvent evt) {} public static void ReadLogfile() { File dir = null; File Files[]; String sLine; DefaultTableModel model = new DefaultTableModel(); String columnNames[] = {"No.", "Discripion", "Text", "Date"}; model.addColumn("No."); model.addColumn("Discription"); model.addColumn("Text"); model.addColumn("Date"); dir = new File("c:/TestLogs"); Files = dir.listFiles(); if(Files != null) { for(int i=0;i<Files.length;i++) { try { if(Files[i].isFile()) { //System.out.println("Verarbeite: " + Files[i]); BufferedReader in = new BufferedReader( new FileReader (Files[i])); sLine = in.readLine(); while(sLine != null ) { if(sLine.equals("")) { } else { if (sLine.substring(0,1).equals("[")) { model.addRow(new Object[]{sLine.substring(0,3),sLine.substring(6,10),sLine.substring(16,54),sLine.substring(54,80)}); } } sLine = in.readLine(); } table.setModel(model); table.repaint(); in.close(); } } catch(Exception e) { System.out.println("Exception "+e); } } } }}