Ola novamente!
Vou ver se consigo explicar o que estou precisando.
Eu criei a seguinte interface:
public interface CommandButtomListener
{
abstract void pointerPressed(int x, int y, int tag);
abstract void pointerReleased(int x, int y, int tag);
}
Em um form eu implemento essa interface para que um botao que eu criei usando CutomItem chame esses Eventos.
No meu botão eu fiz assim veja:
public class CommandButtom extends CustomItem
{
public int tag;
private int w, h;
private Displayable listener;
public CommandButtom(String label)
{
this(label, null, 40, 20);
}
public CommandButtom(String label, Displayable listener)
{
this(label, listener, 40, 20);
tag = 0;
}
public CommandButtom(String label, Displayable listener, int w, int h)
{
super(label);
this.listener = listener;
this.w = w;
this.h = h;
setItemCommandListener((ItemCommandListener) listener);
tag = 0;
}
protected int getMinContentHeight()
{
return 20;
}
protected int getMinContentWidth()
{
return 40;
}
protected int getPrefContentHeight( int width )
{
return getMinContentHeight();
}
protected int getPrefContentWidth( int height )
{
return getMinContentWidth();
}
protected void paint( Graphics g, int width, int height )
{
g.setColor(127, 127, 127);
g.fillRect(0, 0, width, height);
g.setColor(255, 255, 255);
g.drawRect(0, 0, width, height);
}
protected void pointerPressed(int x, int y)
{
//Aqui eu preciso chamar o evento no listener
}
protected void pointerReleased(int x, int y)
{
//E aqui tambem
}
}
Viram o que eu preciso? Eu preciso chamar o evento do meu form que implementou o CommandButtomEventListener (eu criei). Eu tenho uma referencia do form em uma variavel privada chamada “listener”. Como eu posso fazer isso ? Resumindo como chamar um metodo que foi implementado de uma interface, não sei se fui claro nessa explicação, qualquer coisa perguntem obrigado!