
//Titel:        Layout
//Version:
//Copyright:    Copyright (c) 1999
//Autor:       Ihr Name
//Organisation:      Ihre Organisation
//Beschreibung:  Ihre Beschreibung

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

import java.awt.event.*;

// Schalter mit einem Panel, 
// im Panel dann GridBagLayout

public class GridBagLayout04a extends JFrame {

  JLabel jLabel1 = new JLabel();
  JTextField TName = new JTextField();

  JLabel jLabel2 = new JLabel();
  JTextField TMatrNr = new JTextField();
  JTextField TUNummer = new JTextField();

  JProgressBar jProgressBar1 = new JProgressBar();

  JButton BnUp = new JButton();
  JButton BnDown = new JButton();

  public GridBagLayout04a() {
    setSize(400, 300);
    setTitle("GridBagLayout 04a. Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {
    this.getContentPane().setLayout( new GridBagLayout() );

    jLabel1.setText("Name");
    TName.setText("-");

    jLabel2.setText("Nummern");
    TMatrNr.setText("(Matr.-Nr)60%");
    TUNummer.setText("(Unummer)40%");

    BnUp.setText("Up");
    BnUp.addActionListener(
      new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BnUp_actionPerformed(e);
      }
    });
    BnDown.setText("Down");
    BnDown.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        BnDown_actionPerformed(e);
      }
    });

    jProgressBar1.setMaximum(100);
    jProgressBar1.setMinimum(0);

    jProgressBar1.setValue( 15 );



    this.getContentPane().add(jLabel1,
        new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.NONE,
            new Insets(0,20,30,20), 0, 0));

    this.getContentPane().add(TName,
        new GridBagConstraints(
             1, 0, 2, 1, 100.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,20,30,20), 0, 0));

    this.getContentPane().add(jLabel2,
        new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTH,
            GridBagConstraints.NONE,
            new Insets(0,20,0,0), 0, 0));

    this.getContentPane().add(TMatrNr,
        new GridBagConstraints(
              1, 1, 1, 1, 7000.0, 0.0
            ,GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,20,0,0), 0, 0));

    this.getContentPane().add(TUNummer,
        new GridBagConstraints(
            2, 1, 1, 1, 30.0, 0.0
            ,GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,20,0,20), 0, 0));


   // --------------------------
            // Progressbar
    this.getContentPane().add(jProgressBar1,
        new GridBagConstraints(0, 2, 3, 1, 100.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(40,20,0,20), 0, 21));  //  21  zusätzliche Höhe


   // --------------------------
            // Schalter
     JPanel panelBn = new JPanel();
     panelBn.setLayout( new GridBagLayout() );
     //panelBn.setBackground(Color.green);

    this.getContentPane().add(panelBn,
        new GridBagConstraints(0, 3, 3, 1, 100.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(40,20,0,20), 0, 0));


     JPanel panelBnL = new JPanel();
     panelBnL.setLayout( new FlowLayout() );
     //panelBnL.setBackground(Color.red);

     JPanel panelBnR = new JPanel();
     panelBnR.setLayout( new FlowLayout() );
     //panelBnR.setBackground(Color.blue);

    panelBn.add(panelBnL,
        new GridBagConstraints(0, 0, 1, 1, 50.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,0,0,0), 0, 0));

    panelBn.add(panelBnR,
        new GridBagConstraints(1, 0, 1, 1, 50.0, 0.0
            ,GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,0,0,0), 0, 0));


    panelBnL.add(BnDown);
    panelBnR.add(BnUp);
    setFonts(getContentPane(), 18);   
  } // setGUI


 private void setFonts(Container cont, int size) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
      Component c = cont.getComponent(i);
      if (c instanceof JPanel) {
        setFonts((JPanel) c, size);
      } else {
        c.setFont(new Font("Arial", Font.BOLD, size));
      }
    }
  }


  void BnUp_actionPerformed(ActionEvent e) {
    jProgressBar1.setValue( jProgressBar1.getValue()+1 );
  }

  void BnDown_actionPerformed(ActionEvent e) {
    jProgressBar1.setValue( jProgressBar1.getValue()-1 );
  }

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

}


