Skip to main content

ActionListeners on touchscreen

4 replies [Last post]
brkx
Offline
Joined: 2009-03-13

Can anyone please explain how exactly does the ActionListener work because I can't seem to get a grip on it

I've created a Container which contains a few Buttons and I've added a form as an ActionListener to every single Button but when I click on the Button on the emulator the Action isn't invoked

anyone have a reason why?
Did I manage to forget something?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
myinstinct
Offline
Joined: 2008-10-24

we'd probably need to see your code to help

brkx
Offline
Joined: 2009-03-13

[code]public class MyContainer extends Container {
private Button button1;
private Button button2;
private Button button3;

public MyContainer (Command command1, Command command2, Command command3){
setLayout (new CoordinateLayout (100, 100));

button1 = new Button (command1);
button2 = new Button (command2);
button3 = new Button (command3);

prepareButton (button1); //sets its style and relative position
prepareButton (button2);
prepareButton (button3);

addComponent (button1);
addComponent (button2);
addComponent (button3);
}
//...
// getters for buttons
//...
}[/code]

..and then the snippet from the Form which implements ActionListener
[code]
...
MyComponent myComponent = new MyComponent (command1, command2, command3);
myComponent.getButton1().addActionListener(this);
myComponent.getButton2().addActionListener(this);
myComponent.getButton3().addActionListener(this);
...
[/code]

and I try to cover the action in actionPerformed but not a single event occurs when I click on the button on touchscreen

Klemens

Have you tried the same without using Commands, just passing the title
of the button? Actually I don't see the need for using commands. Just an
idea, don't know if it has any effect, it should behave the same way.
But I use a lot of Buttons in my Application and they all react on
touchscreen events (at least on the emulator).
Another idea: Have you tried using another layout?

On 08.05.2009 18:03, lwuit-users@mobileandembedded.org wrote:
> [code]public class MyContainer extends Container {
> private Button button1;
> private Button button2;
> private Button button3;
>
> public MyContainer (Command command1, Command command2, Command command3){
> setLayout (new CoordinateLayout (100, 100));
>
> button1 = new Button (command1);
> button2 = new Button (command2);
> button3 = new Button (command3);
>
> prepareButton (button1); //sets its style and relative position
> prepareButton (button2);
> prepareButton (button3);
>
> addComponent (button1);
> addComponent (button2);
> addComponent (button3);
> }
> //...
> // getters for buttons
> //...
> }[/code]
>
>
> ..and then the snippet from the Form which implements ActionListener
> [code]
> ...
> MyComponent myComponent = new MyComponent (command1, command2, command3);
> myComponent.getButton1().addActionListener(this);
> myComponent.getButton2().addActionListener(this);
> myComponent.getButton3().addActionListener(this);
> ...
> [/code]
>
> and I try to cover the action in actionPerformed but not a single event occurs when I click on the button on touchscreen
> [Message sent by forum member 'brkx' (brkx)]
>
> http://forums.java.net/jive/thread.jspa?messageID=345547
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

brkx
Offline
Joined: 2009-03-13

I've used BoxLayout before.. didn't work either. I'm using CoordinateLayout simply for some graphics problems

And yes, I've tried using only Buttons without Commands but that didn't work either

It just crossed my mind - [b]MyContainer isn't located in the contentPane but on the north of the Form instead of the classical Title[/b]. This is the only thing I can think off which can be problematic