Skip to main content

ActionPerformed

5 replies [Last post]
heziflash
Offline
Joined: 2008-06-03
Points: 0

Hi

In my program i defined 2 buttons (b1 and b2)
here is the code:

final Button b1 = new Button("Sel");
b1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
}
});
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

}
});
final Button b2 = new Button("Brkpoint");
b2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
}
});

now i want to add a soft button called "help" but i want it to be only 1 button, and if i choose b1 and "help" it will show me the Dialog.show() of b1 and if i choose b2 , it will show me the Dialog.show() of b2.
Can i do it?
Hezi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Hi Hezi,
did you import the events package?

> Hi Shai
>
> What is worng in my code (the compiler does not recognize
> FocusListener() )
>
> cig.setFocusable(true);
> cig. addFocusListener(new FocusListener(){
>
> public void actionPerformed(ActionEvent
> arg0) {
>
> long time = System.currentTimeMillis();
>
> _LearnHowManyCig++;
> }
> });
>
> Thanks,
> Hezi
> [Message sent by forum member 'heziflash' (heziflash)]
>
> http://forums.java.net/jive/thread.jspa?messageID=285710
>
> ---------------------------------------------------------------------
> 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

heziflash
Offline
Joined: 2008-06-03
Points: 0

Hi Shai

What is worng in my code (the compiler does not recognize FocusListener() )

cig.setFocusable(true);
cig. addFocusListener(new FocusListener(){

public void actionPerformed(ActionEvent arg0) {

long time = System.currentTimeMillis();

_LearnHowManyCig++;
}
});

Thanks,
Hezi

Francis De Brabandere

actionperformed is a actionlistener method (don't you use an IDE that
autocompletes code?), try this:

cig.addFocusListener(new FocusListener() {

public void focusGained(Component arg0) {
//code here
}

public void focusLost(Component arg0) {
//code here
}
});

On Thu, Jul 10, 2008 at 6:17 PM, wrote:
> Hi Shai
>
> What is worng in my code (the compiler does not recognize FocusListener() )
>
> cig.setFocusable(true);
> cig. addFocusListener(new FocusListener(){
>
> public void actionPerformed(ActionEvent arg0) {
>
> long time = System.currentTimeMillis();
>
> _LearnHowManyCig++;
> }
> });
>
> Thanks,
> Hezi
> [Message sent by forum member 'heziflash' (heziflash)]
>
> http://forums.java.net/jive/thread.jspa?messageID=285710
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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

Shai Almog

Hi,
if I understand correctly you want the help command to be aware of
which button is selected by the user.

This is easy to do, in the command code just ask:
if(b1.hasFocus()) {
// show b1 help
} else {
if(b2.hasFocus()) {
// show b2 help
}
}

Thanks,
Shai.

> Hi
>
> In my program i defined 2 buttons (b1 and b2)
> here is the code:
>
>
>
> final Button b1 = new Button("Sel");
> b1.addActionListener(new ActionListener() {
>
> public void actionPerformed(ActionEvent evt) {
> }
> });
> b1.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent arg0) {
>
> }
> });
> final Button b2 = new Button("Brkpoint");
> b2.addActionListener(new ActionListener() {
>
> public void actionPerformed(ActionEvent evt) {
> }
> });
>
>
> now i want to add a soft button called "help" but i want it to be
> only 1 button, and if i choose b1 and "help" it will show me the
> Dialog.show() of b1 and if i choose b2 , it will show me the
> Dialog.show() of b2.
> Can i do it?
> Hezi
> [Message sent by forum member 'heziflash' (heziflash)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284753
>
> ---------------------------------------------------------------------
> 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

heziflash
Offline
Joined: 2008-06-03
Points: 0

when i say "choose" i mean "walking" with the "arrows" to b1 or b2 without pushing the "FIRE" button.

Hezi