• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Java Event Handling not understand

 
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am new to GUI concept.My doubt is

1.what is ActionListener? why we are using this?
2.what is actionPerformed method? shall i change this name as "actionOperation" or something related to this? why i can't able to modify this method name?
3.What is ActionEvent argument? why it is used ?
4.Why we are using constructor in this program? is event handling is only implemented with constructor?
5.why we are importing "awt.event" package? it is already in "awt.*;" know? then we are again implementing this package? "awt.event" is present inside the "awt" only know?
6.Why should i need to implement "setLayout(null)"method? it is already in null,then whats the use of this method?

Sorry for my bad english.Please kindly help me to understand.Thanks in advance
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vinoth vino wrote:
1.what is ActionListener? why we are using this?


ActionListener is an interface in java that "listens" to events

vinoth vino wrote:
2.what is actionPerformed method? shall i change this name as "actionOperation" or something related to this? why i can't able to modify this method name?


The actionPerformed is the method defined in the ActionListener interface. This method cannot be renamed if you are to implement ActionListener. Renaming such method means different thing to java anyway.

vinoth vino wrote:
3.What is ActionEvent argument? why it is used ?


The ActionEvent is a class representing an action. It is used in the actionPerformed method to determine what your action was (eg button click)

vinoth vino wrote:
4.Why we are using constructor in this program? is event handling is only implemented with constructor?


Given your program, it is extending Frame and implementing ActionListener - meaning your class AEvent is a Frame AND is a ActionListener. Both "extends" and "implements" keywords means "IS-A" relationship.

Every program you write has a default, no-args constructor created by compiler unless you explicitly declare one with one or more parameters.

Event handling can be achieved in many ways depending on what "event" you have in mind. Mouse clicks/movement, key strokes, button clicks etc


vinoth vino wrote:
5.why we are importing "awt.event" package? it is already in "awt.*;" know? then we are again implementing this package? "awt.event" is present inside the "awt" only know?


The awt package and awt.event package are 2 separate packages. Importing awt package does not include subclasses (packages) under it, hence awt.event package need to import separately

vinoth vino wrote:
6.Why should i need to implement "setLayout(null)"method? it is already in null,then whats the use of this method?


The setLayout method is use to set a layout manager to the component. Every GUI component has a default layout. Frame is BorderLayout, Panel is FlowLayout.

Setting it "null" makes the layout null or no layout. Null layout is really absolute positioning of components.



Have a look at the GUI java tutorial for more info.
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnqqqqqqqqqqqqqqqqq so much it really helped me alot
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!