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

public class Thread08a extends JFrame {

  double summe;
  JButton BnStart = new JButton("Start");
  JLabel label;

  //Frame konstruieren
  public Thread08a() {
    setSize(500, 320);
    setLocation(100,10);
    setTitle("Thread08");

    label = new JLabel();
    label.setFont( new Font("Arial", Font.BOLD,32));
    label.setText( "0" );

    this.getContentPane().add(label, BorderLayout.CENTER);

    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    JPanel pn = new JPanel();
    pn.setLayout( new FlowLayout() );

    pn.add(BnStart);
    this.getContentPane().add(pn, BorderLayout.SOUTH);
    BnStart.setFont( new Font("Arial", Font.BOLD,32));

    BnStart.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BnStart_Click();
      }
    });

    setLocation(400,30);
    setVisible(true);
  }

  private void  BnStart_Click() {
    double a, b, diff;
     
    myThread [] mT = new myThread[4];

    a=0.0;
    diff = (10.0-0.0)/mT.length;
    b=0.0;
    for (int i=0; i<mT.length; i++) {
      b+=diff;
      mT[i] = new myThread(a,b);
      a+=diff;
    }
    summe = 0;
    label.setText( "0" );

    for (int i=0; i<mT.length; i++) {
      mT[i].start();
    }

	try {
     for (int i=0; i<mT.length; i++) {
      mT[i].join();
     }
    }
    catch (InterruptedException e) {
    }
    label.setText( ""+summe );

  } // Start




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


class myThread extends Thread {

  double _a, _b;

  public myThread (double a, double b) {
    System.out.println("a: "+a+"  b:"+b);
     _a =a;
     _b = b;
  }

  public void run() {
    int time;
    int n=10000;
    double lsumme=0;
    double h = (_b-_a)/n;
    double x, y, xe;
    x=_a;
    xe = _b-h;
    for (int i=0; i<n; i++) {
      lsumme+=(2.0*x-3.0)*h;
      x+=h;
    } // for
    summe+=lsumme;
    
  } // calc



}


}




