• 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

Why this object gets null in actionPerformed

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,
I was trying to develop following simple program but have some questions. Could you please help me solve same..

Q1: Why this mp gets null in actionPerformed? Moment I am clicking it on "Changeuser/login" option under File Menu it sends error on console.
Q2: Can you help me to wrtie this code in better fashion?
Q3: Is this style of coding will manage the system Memory or this wil take more than required?
I would appreciate if some one will answer it pointwise to understand it better.

regards,
arun

 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I looked over your class and patched it up... Here are some of the biggest problems I noticed...
  • You were adding the action listener in a really strange way... The usual way to do this is to create one instance of the class and call addActionListener( myActionListener ) on each button you want to listen to. I think that your reference to mp got lost due to the way you were using the actionlistener.
  • You don't need a seperate JFrame to build the menu bar... it is easier and better to do it inside the frame that is actually using the menu bar.
  • The way that you were figuring out which button or menuitem was pushed was strange... it is easier to use the action command of the button that was pressed to figure it out...
  • You need to call validate() instead of repaint() in your makePanel. Repaint should be called if only the graphics drawn on components are changed. If components are added or removed, you need to re - validate() the component.
  • You can make your actionlistener an inner class to prevent the reference to mp getting passed all over the place...
  • That's all for now...


  • Here's the modified code...



    -Nate
    [ May 08, 2002: Message edited by: Nathan Pruett ]
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic