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

// 1. Beispiel mit TextField und Schaltern



public class Bsp_02 extends JFrame {

    JButton BnInput1 = new JButton("Input1");
    JButton BnInput2 = new JButton("Input2");
    JButton BnInput3 = new JButton("Input3");

    public Bsp_02() {
      setSize(400, 200);
      setLocation(100,100);
      setGUI();
    }

    private void setGUI() {
      BnInput1.setFont( new Font("Arial", Font.BOLD,18)  );
      BnInput2.setFont( new Font("Arial", Font.BOLD,18)  );
      BnInput3.setFont( new Font("Arial", Font.BOLD,18)  );

      JPanel pn = new JPanel();
      pn.setLayout ( new FlowLayout() );
      pn.add(BnInput1);
      pn.add(BnInput2);
      pn.add(BnInput3);

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

      BnInput1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          BnInput1_Click();
        }
      });
      BnInput2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          BnInput2_Click();
        }
      });
      BnInput3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          BnInput3_Click();
        }
      });

    }

  private void BnInput1_Click() {
    Eingabe(1);
  }
  private void BnInput2_Click() {
    Eingabe(2);
  }
  private void BnInput3_Click() {
    Eingabe(3);
  }

  private void Eingabe(int nr) {
    Input d = new Input(this,nr);
    d.setVisible(true);
  }

  //Ü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);
    }
  }  // jbinit2

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

}


class Input extends JDialog {

  JLabel jLabel1[];
  JTextField TName[];

  JButton BnOk = new JButton();
  JButton BnESC = new JButton();

  int _nr;

  public Input(Frame f, int nr) {
    super(f,true);  //  parent,  modal=true
    _nr = nr;
    setGUI();
  }

  private void setGUI() {
    int i;
    setLocation(300,300);
    setSize(400, 100 + _nr*100);
    setTitle("1. Eingabefenster mit GridBagLayout");
    this.getContentPane().setLayout( new GridBagLayout() );

    jLabel1 = new JLabel[_nr ];
    TName = new JTextField[_nr ];

    for (i=0; i<_nr; i++) {
      jLabel1[i] = new JLabel( Integer.toString(i+1)+  ".Eingabe");
      TName[i] = new JTextField("");
      jLabel1[i].setFont( new Font("Arial", Font.BOLD,18)  );
      TName[i].setFont( new Font("Arial", Font.BOLD,18)  );
    }

    for (i=0; i<_nr; i++) {
      this.getContentPane().add(jLabel1[i],
           new GridBagConstraints(0, i, 1, 1, 0.0, 0.0
              ,GridBagConstraints.WEST, GridBagConstraints.NONE,
              new Insets(0,25,40,0), 0, 0));

      this.getContentPane().add(TName[i],
          new GridBagConstraints(1, i, 1, 1, 10000.0, 0.0
              ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
              new Insets(0,25,40,25), 0, 0));
    }


    BnOk.setText("Ok");
    BnESC.setText("Abbruch");
    BnOk.setFont( new Font("Arial", Font.BOLD,18)  );
    BnESC.setFont( new Font("Arial", Font.BOLD,18)  );

    BnOk.setPreferredSize( BnESC.getPreferredSize() );



    JPanel pn = new JPanel();
    pn.add(BnOk);
    pn.add(BnESC);
//    pn.setBackground(Color.green);
    this.getContentPane().add(pn,
           new GridBagConstraints(0, _nr, 2, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(0,0,0,0), 0, 0));

    BnOk.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BnOk_Click();
      }
    });
    BnESC.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BnESC_Click();
      }
    });



  }


  private void BnOk_Click() {
      dispose();
  }

  private void BnESC_Click(){
      dispose();
  }

}



