handeling events

From: Triff (neverread_at_yahoo.com)
Date: 12/29/04


Date: Wed, 29 Dec 2004 21:37:54 -0000

I'm quite bad at explaining my problems.....but here goes!

package harmonics;
import java.awt.BorderLayout;
import javax.swing.*;

public class MainProgram
{
 public static JPanel jpanNorth, jpanSouth;

 public static void main(String args[])
 {
  JFrame jfrmMain = new JFrame("Harmonics Program");
  jpanNorth = new JPanel();
  jpanSouth = new JPanel();

  Producer sp = new Producer(jpanSouth);

  jfrmMain.getContentPane().add(jpanNorth, BorderLayout.NORTH);
  jfrmMain.getContentPane().add(jpanSouth, BorderLayout.SOUTH);
  jfrmMain.setSize(500,500);
  jfrmMain.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  jfrmMain.setVisible(true);
 }
}

package harmonics;

import javax.swing.JPanel;
import javax.swing.JSlider;

public class Producer
{
 public static JSlider sliders[];

 public Producer(JPanel pan)
 {
  sliders = new JSlider[10];

  SliderChanger sliderMoved = new SliderChanger();

  for(int i = 0; i < sliders.length; i++)
  {
   sliders[i] = new JSlider(1,0,100,10);
   sliders[i].addChangeListener(sliderMoved);
   pan.add(sliders[i]);
  };
 }
 public static int[] getSliderValues()
 {
  int sliderValues[];
  sliderValues = new int[10];
  for(int i = 0; i < sliders.length; i++)
  {
   sliderValues[i] = sliders[i].getValue();
  };
  return sliderValues;
 }
}

package harmonics;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class SliderChanger implements ChangeListener
{
 public Points p;
 public void stateChanged(ChangeEvent e)
    {

  int sliderValues[] = null;
  for(int i= 0; i < 10;i++)
  {
   sliderValues = new int[10];
   sliderValues = Producer.getSliderValues();
  };
  p = new Points(sliderValues);
  p.printSliderValues();
    }
}

package harmonics;

public class Points
{
 private int SliderValues[];
 private double ScaledSliderValues[];
 private double AllHarmonicValues[][];
 private double NewWaveValues[];
 public Points(int vals[])
 {
  SliderValues = new int[10];
  System.arraycopy(vals, 0, SliderValues, 0, 10);
 }
 public void printSliderValues()
 {
  for(int i= 0; i < 10;i++)
  {
   System.out.print(SliderValues[i] + " ");
  };
  System.out.print("\n");
 }
}

Right so there is the code, and here is my problem. As you can see I can
handle the slider event, but I want to have another class called consumer
which recieves a points object and does stuff with it, how would I do that?
Cheers for any help
Triff
 



Relevant Pages