/* Autor:           Dipl.-Inf., Dipl.-Ing. (FH) Michael Wilhelm
   Firma:           HS Harz, FB AI
   Version:         1.1
   Ersterstellung:  07.06.2006
   Letzte Änderung: 10.11.2010
   Ruft ein Programm mittels Runtime.getRuntime().exec auf
   optional kann auch gewartet werden
*/


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.lang.*;



public class Run01 extends JFrame  {
  JToolBar toolBar = new JToolBar();
  JButton Bn1 = new JButton("Start Notepad");
  JButton Bn2 = new JButton("Start Notepad mit Text");
  JButton Bn3 = new JButton("Start Notepad mit Text (warten)");

  JTextArea editor = new JTextArea("Dies ist eine Zeile\r\nDies ist die 2. Zeile");

  public Run01() {
    this.setTitle("Starten von Notepad.exe");
    this.setLocation(100,100);
    this.setSize(300,300);
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  public void setGUI() {
    this.setSize(new Dimension(500, 300));

    Bn1.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        Bn1_click();
      }
    });
    toolBar.add(Bn1);
    toolBar.addSeparator( new Dimension(20,5) );


    Bn2.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        Bn2_click();
      }
    });
    toolBar.add(Bn2);

    Bn3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Bn3_click();
      }
    });
    toolBar.add(Bn3);


    this.getContentPane().add(toolBar, BorderLayout.NORTH);

    JScrollPane sc = new JScrollPane(editor);
    this.getContentPane().add(sc, BorderLayout.CENTER);
    editor.setFont( new Font("Arial", Font.BOLD,18)  );

  }


  private void Bn1_click() {
    try {
      Runtime.getRuntime().exec("notepad.exe");
    }
    catch (IOException e1) {
    }

  }

  private void Bn2_click() {
    try {
      Runtime.getRuntime().exec("notepad.exe Run01.java");
    }
    catch (IOException e2) {
    }
  }

  private void Bn3_click() {
    try {
      Process p = Runtime.getRuntime().exec("notepad.exe Run01.java");
      p.waitFor();
      System.out.println("Ende von Notepad");
    }
    catch (IOException e1) {
    }
    catch (InterruptedException e1) {
    }
  }  // Bn3


  public static void main(String[] args) {
    if (args.length>0) {
      System.out.println("Anzahl: "+args.length);
      for (String s : args)
        System.out.println(" "+s);
    }
    else {
      System.out.println("Keine Parameter");
    }
    Run01 frame = new Run01();
    frame.setVisible(true);
  }

} // Run01


