Implementing AdjustmentListener

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing AdjustmentListener

Tony Shepherd
I'm writing a plugin which implements ActionListener, which is used for
button controls. Now I want to add a scrollbar to the panel, which requires
AdjustmentListener.

If I try to implement AdjustmentListener, the plugin won't compile - says
that I must declare my class as abstract.  If I declare the class as
abstract the plugin cannot be ran, presumably because an abstract class
cannot be instantiated

I have looked for other plugins that use scrollbars as well as buttons, so
that I can learn from their ource code. The only one I have found is the
famous LiveWire plugin, but I can't dig the source code out of the jar file.

Can anyone tell me hw to add a scrollbar?
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AdjustmentListener

jmutterer
The ConstrastAdjuster class from package ij.plugin.frame implements
AdjustmentListener.

Jerome

On 11/6/06, Tony Shepherd <[hidden email]> wrote:

> I'm writing a plugin which implements ActionListener, which is used for
> button controls. Now I want to add a scrollbar to the panel, which requires
> AdjustmentListener.
>
> If I try to implement AdjustmentListener, the plugin won't compile - says
> that I must declare my class as abstract.  If I declare the class as
> abstract the plugin cannot be ran, presumably because an abstract class
> cannot be instantiated
>
> I have looked for other plugins that use scrollbars as well as buttons, so
> that I can learn from their ource code. The only one I have found is the
> famous LiveWire plugin, but I can't dig the source code out of the jar file.
>
> Can anyone tell me hw to add a scrollbar?
>
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AdjustmentListener

Leon Espinosa
In reply to this post by Tony Shepherd
This works for me...


//------ Test_Slider.java ----------

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class Test_Slider extends JFrame implements PlugIn  {

     private JTextField textFieldR;

     public void run(String arg) {
         JFrame sliderFrame = new JFrame("Slider");
         Container cont = sliderFrame.getContentPane();
         cont.setLayout(new FlowLayout());

         JSlider sliderR = new JSlider(0,100,100);
         sliderR.setPaintTicks(true);
         sliderR.setPaintLabels(true);
         sliderR.setMajorTickSpacing(20);
         sliderR.setMinorTickSpacing(5);

         textFieldR = new JTextField("100", 5);

         sliderR.addChangeListener(new ChangeListener() {
             public void stateChanged(ChangeEvent e) {
                 JSlider sourceR = (JSlider) e.getSource();
                 textFieldR.setText(""+sourceR.getValue());
             }
         });


         cont.add(sliderR);
         cont.add(textFieldR);
         sliderFrame.setBounds(250,250,300,150);
         sliderFrame.setVisible(true);

     }
}

//---- end Test_Slider.java ---



Leon


Le 6 nov. 06 à 22:30, Tony Shepherd a écrit :

> I'm writing a plugin which implements ActionListener, which is used  
> for
> button controls. Now I want to add a scrollbar to the panel, which  
> requires
> AdjustmentListener.
>
> If I try to implement AdjustmentListener, the plugin won't compile  
> - says
> that I must declare my class as abstract.  If I declare the class as
> abstract the plugin cannot be ran, presumably because an abstract  
> class
> cannot be instantiated
>
> I have looked for other plugins that use scrollbars as well as  
> buttons, so
> that I can learn from their ource code. The only one I have found  
> is the
> famous LiveWire plugin, but I can't dig the source code out of the  
> jar file.
>
> Can anyone tell me hw to add a scrollbar?
>

Leon Espinosa
[hidden email]

Laboratoire des Rickettsies du Pr. RAOULT
UMR CNRS 6020
Fac. de Medecine de la Timone
27 Bd Jean Moulin
13005 Marseille

tel  04 91 38 55 17
fax 04 91 38 77 72

portable  06 79 25 97 40
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AdjustmentListener

Tony Shepherd
In reply to this post by Tony Shepherd
Thanks Leon, that gives me a slide bar. But Now I can't add BUTTONS to the
panel, because I can't implement ActionListener, as..

extends JFrame implements PlugIn, ActionListener

causes the same complaint about abstract classes.

As Jerome pointed out, the ContrastAdjuster panel contains both buttons and
slidebars. How does it do it!?

NB if I include
package ij.plugin.frame;

instead of
import ij.plugin.frame.*;

then 'superclass Jframe not found'
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AdjustmentListener

Tony Shepherd
In reply to this post by Tony Shepherd
Thanks Leon, that gives me a slide bar. But Now I can't add BUTTONS to the
panel, because I can't implement ActionListener, as..

extends JFrame implements PlugIn, ActionListener

causes the same complaint about abstract classes.

As Jerome pointed out, the ContrastAdjuster panel contains both buttons and
slidebars. How does it do it!?

NB if I include
package ij.plugin.frame;

instead of
import ij.plugin.frame.*;

then 'superclass Jframe not found'
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AdjustmentListener

Leon Espinosa
The same code + one test button...


import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test_Slider extends JFrame implements PlugIn  {

     private JTextField textFieldR;

     public void run(String arg) {
         JFrame sliderFrame = new JFrame("Slider");
         Container cont = sliderFrame.getContentPane();
         cont.setLayout(new FlowLayout());

         JSlider sliderR = new JSlider(0,100,100);
         sliderR.setPaintTicks(true);
         sliderR.setPaintLabels(true);
         sliderR.setMajorTickSpacing(20);
         sliderR.setMinorTickSpacing(5);

         textFieldR = new JTextField("100", 5);

         sliderR.addChangeListener(new ChangeListener() {
             public void stateChanged(ChangeEvent e) {
                 JSlider sourceR = (JSlider) e.getSource();
                 textFieldR.setText(""+sourceR.getValue());
             }
         });


         JButton button = new JButton("test");
         button.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                IJ.showMessage("OK test");
             }
         });

         cont.add(sliderR);
         cont.add(textFieldR);
        cont.add(button);
         sliderFrame.setBounds(250,250,300,150);
         sliderFrame.setVisible(true);

     }
}




Le 7 nov. 06 à 13:30, Tony Shepherd a écrit :

> Thanks Leon, that gives me a slide bar. But Now I can't add BUTTONS  
> to the
> panel, because I can't implement ActionListener, as..
>
> extends JFrame implements PlugIn, ActionListener
>
> causes the same complaint about abstract classes.
>
> As Jerome pointed out, the ContrastAdjuster panel contains both  
> buttons and
> slidebars. How does it do it!?
>
> NB if I include
> package ij.plugin.frame;
>
> instead of
> import ij.plugin.frame.*;
>
> then 'superclass Jframe not found'
>

Leon Espinosa
[hidden email]

Laboratoire des Rickettsies du Pr. RAOULT
UMR CNRS 6020
Fac. de Medecine de la Timone
27 Bd Jean Moulin
13005 Marseille

tel  04 91 38 55 17
fax 04 91 38 77 72

portable  06 79 25 97 40
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AdjustmentListener

Volker Baecker
In reply to this post by Tony Shepherd
Hello Tony,
you must implement the method
public void actionPerformed( ActionEvent e )
of the ActionListener interface.
Or alternatively you do not let your class implement the ActionListener
but you use an anonymous ActionListener like in

button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            IJ.showMessage("OK test");
            }
        });

The package statement is a declaration of a package not an include. It
means that your code will be in the package ij.plugin.frame.

By the way, you can get the source code of the LiveWire plugin from the
sourceforge cvs repository: http://sourceforge.net/cvs/?group_id=171446

Volker Baecker
 


Tony Shepherd a écrit :

> Thanks Leon, that gives me a slide bar. But Now I can't add BUTTONS to the
> panel, because I can't implement ActionListener, as..
>
> extends JFrame implements PlugIn, ActionListener
>
> causes the same complaint about abstract classes.
>
> As Jerome pointed out, the ContrastAdjuster panel contains both buttons and
> slidebars. How does it do it!?
>
> NB if I include
> package ij.plugin.frame;
>
> instead of
> import ij.plugin.frame.*;
>
> then 'superclass Jframe not found'
>
>  

--
passerelle antivirus du campus CNRS de Montpellier
--