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

import java.awt.event.*;


import java.io.*;
import java.awt.image.*;

import java.awt.color.*;


public class Slider1 extends JFrame {


  JLabel lSlider = new JLabel("Wert");
  JTextField tSlider= new JTextField("50");

  JSlider slider = new JSlider();


  public Slider1() {
    setTitle("1. Slider Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setSize(600,200);
    setGUI();
  }


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

  // -----------------------------
  this.getContentPane().add(lSlider,
        new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0,10,20,20), 0, 0));

  this.getContentPane().add(tSlider,
        new GridBagConstraints(1, 0, 1, 1, 100.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,10,20,20), 0, 0));

  this.getContentPane().add(slider,
        new GridBagConstraints(0, 1, 2, 1, 100.0, 0.0
            ,GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0,10,20,20), 0, 0));


    slider.setMinimum(0);
    slider.setMaximum(255); // hunderstels
    slider.setValue(50);

   slider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderchangeState(evt);
            }
   });

   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));
      }
   }

  // wird aufgerufen, wenn der linke Slider verändert wird
  private void sliderchangeState(javax.swing.event.ChangeEvent evt) {
     int i = (int) slider.getValue();
     tSlider.setText( Integer.toString(i) );
  }



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


}


