Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

handeling events
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




Report this thread to moderator Post Follow-up to this message
Old Post
Triff
12-30-04 01:58 AM


Re: handeling events
Triff wrote:
> I'm quite bad at explaining my problems.....but here goes!
>
[snip code]
> 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

You could just do this:
new Consumer(point);

Make sure the Consumer has a constructor which accepts a point object.

--
-------------
- ByteCoder -           ...I see stupid people
-------------
Curiosity *Skilled* the cat

Report this thread to moderator Post Follow-up to this message
Old Post
ByteCoder
12-30-04 01:58 AM


Re: handeling events
You could either create a new consumer instance every time.

Consumer c = new Consumer() ;
c.doStuff(points) ;

or maybe just have a global consumer:

consumer.doStuff(points) ;

--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking... "


Report this thread to moderator Post Follow-up to this message
Old Post
Fahd Shariff
12-30-04 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:49 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.