• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CheckboxMenuItem

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Friends,
Can CheckboxMenuItem generate ActionEvent?

Though CheckBoxMenuItem generates ItemEvent but it should generate ActionEvent as well b/c addActionListener method is
inherited from its super class MenuItem...
I tried with some code, it's working with Menu(another subclass of MenuItem) but not with CheckBoxMenuItem..
please Help!

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nasir Khan:

Though CheckBoxMenuItem generates ItemEvent but it should generate ActionEvent as well b/c addActionListener method is
inherited from its super class MenuItem...


brilliant logic ! its really amazing . keep it up.
with due respect to above theory Label should generate FocusEvent, KeyEvent, MouseEvent. because component class
having addXXXListener method of corresponding events.
and Label is the subclass of component.
rest of all you understand easily.
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes naveen ,all components inherit everything from Component class.A Label can generate MouseEvent,MouseMotionEvent etc.
Here's an example
import java.awt.*;
import java.awt.event.*;
class label extends Frame{ Label l;
label(){ setLayout(new FlowLayout());
l=new Label("come as you are");
l.setBackground(Color.pink);
add(l);
setSize(300,300);
setVisible(true);
}
public static void main(String s[]){
final label e=new label();
e.l.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent d){
e.l.setText("as you were");}
public void mouseExited(MouseEvent d){
e.l.setText("as i want you to be");
} });

}
}
Not only this you can use paint method to all of the components as well.You can draw a small circle or an image on a
Button,on a Label,on a CheckBox etc etc.
That's why I'm confused in the case of CheckboxMenuItem which 'is a' MenuItem basically.so if a MenuItem can generate a
ActionEvent why CheckboxMenuItem can't ??....

[This message has been edited by Nasir Khan (edited December 20, 2000).]
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess, and I am not positive on this since I didn't see anything in the API and I haven't looked at the source code of the CheckboxMenuItem class, is that CheckboxMenuItem class overrides addActionListener and passes in a null value so that no action is performed or they have no body for the overridden method. They don't put it in the API since this isn't a method that you would call since it doesn't do anything.

Just a hunch,
Bill
[This message has been edited by bill bozeman (edited December 20, 2000).]
 
naveen sahu
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nasir Khan:
yes naveen ,all components inherit everything from Component class.A Label can generate MouseMotionEvent etc.


oh my god ! you again through a hydrogen bomb named "MouseMotionEvent" . i think that event is soloely written by you . please send me your copy of java api & jdk also . i think i have to update my knowledge also.
and last thing about labels ....
refer RHE
chapter no. 11
chapter name . Components.
page no. 322
line no. 18 to 19.
which says that "The Simplest AWT component is the label. Labels do not respond to user input, and they do not send out any events."
the above statement is from RHE indian edition.
i have not worked on the strategy named "Permutation & Combination" . because for this strategy my whole life period is too short. and i do not believe in "reincarnation"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic