Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I am using BlueJ and having issues with this part of my code:
Java
slideSize = new JSlider(JSlider.HORIZONTAL,1, 10, 5);
       slider.setBorder(BorderFactory.createTitledBorder("Pressure Control"));
       slider.setMinorTickSpacing(1);
       slider.setPaintTicks(true);
       slider.setPreferredSize( new Dimension( 500, 60 ) );
       add(slider,  BorderLayout.PAGE_END);
       slider.addChangeListener(this);



Gives this compile error:



method addChangeListener in class javax.swing.Jslider cannot be applied to given types;

required: java .swing.event.ChangeListener
found:ExampleSoloution8_2

reason: actual argument ExampleSoloution8_2 cannot be converted to javax.swing.event.ChangeListener by method invocation conversion

The operator that you use here cannot be used for the type of value that you are using for it. You are either using the wring type here, or the wrong operator.

Any tips?

Thanks!
Posted
Updated 19-Jan-13 5:46am
v3
Comments
Richard MacCutchan 19-Jan-13 13:04pm    
There is not much that can be added to that diagnostic information, it explains it all.
Edward Prentice 19-Jan-13 13:11pm    
I am not yet very good at interpreting the errors given,

I can compile this :

slider = new JSlider(JSlider.HORIZONTAL,minValue,maxValue,initValue);
add(slider, BorderLayout.SOUTH);
slider.addChangeListener(this);

in a separate main and cannot see the difference.
Richard MacCutchan 19-Jan-13 13:29pm    
slider.addChangeListener(this);
The parameter this is not a ChangeListener type. You need to create a proper event that is.
Edward Prentice 19-Jan-13 13:33pm    
I was missing the latter on top of my code:
implements ChangeListener, ActionListener .

It now works with (this)

Thanks very much!
Edward Prentice 19-Jan-13 13:30pm    
Fantastic, thank you!

1 solution

OP posted:
I was missing the latter on top of my code: implements ChangeListener, ActionListener . It now works with (this) Thanks very much!

Posting it to pop it out of unanswered list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900