• 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 ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

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.


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...

    [ May 08, 2002: Message edited by: Nathan Pruett ]
    It runs on an internal combustion engine. This ad does not:
    a bit of art, as a gift, the permaculture playing cards
      Bookmark Topic Watch Topic
    • New Topic