
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Tutorial_01a extends JFrame {

  JTextField editzeile = new JTextField();
  JTextArea editor = new JTextArea();

  //Frame konstruieren
  public Tutorial_01a() {
    setSize(1000, 700);
    setTitle("1. Tutorial: JFrame");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  // wenn close, dann
    setGUI();
  } // create


  void setGUI() {
    JButton bnBsp1 = new JButton("Beispiel1");		// Schalter definieren
    JButton bnBsp2 = new JButton("Beispiel2");		// Schalter definieren
    JButton bnEsc = new JButton("Abbrechen");		// Schalter definieren

    editzeile.setFont( new Font("Arial", Font.BOLD,28));
    editzeile.setText("10");  // N =10

    this.getContentPane().add(editzeile, BorderLayout.NORTH);

      // Center
    editor.setFont( new Font("Arial", Font.BOLD,28));
    editor.setText("");
    getContentPane().add( new JScrollPane(editor), BorderLayout.CENTER);

      // South
    bnBsp1.setFont( new Font("Arial", Font.BOLD,28));
    bnBsp2.setFont( new Font("Arial", Font.BOLD,28));
    bnEsc.setFont( new Font("Arial", Font.BOLD,28));

    JPanel panelBn = new JPanel();
    panelBn.setLayout( new FlowLayout( FlowLayout.RIGHT) );
    panelBn.add(bnBsp1);
    panelBn.add(bnBsp2);
    panelBn.add(bnEsc) ;
    this.getContentPane().add(panelBn, BorderLayout.SOUTH);

    bnBsp1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        bnBsp1_Click();
      }
    });
    bnBsp2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        bnBsp2_Click();
      }
    });
    bnEsc.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        bnEsc_Click();
      }
    });

  }  // setGUI



  void bnBsp1_Click() {
    editor.setText("" );  
    for (int i=0; i<10; i++) {
      editor.append("Beispiel: "+(i+1)+"\n" );  // Editorinhalt löschen 
    }
  }  // bn_Bsp1

  void bnBsp2_Click() {
    String sValue = editzeile.getText();
    int n;
    try {
      editor.setText("" );  
      n = Integer.parseInt(sValue);
      for (int i=1; i<=n; i++) {
       editor.append("Index: "+i+"\n" ); 
      }
    }
   catch ( NumberFormatException e ){ 
       editor.setText("Konvertierungsfehler: "+sValue );
    }

  }  // bn_Bsp2
  

  void bnEsc_Click() {
    this.dispose();
    System.exit(0);
  }

 
  public static void main(String[] args) {
    Tutorial_01a frame = new Tutorial_01a();
    frame.setVisible(true);
  }


}
