calling another function in nested class

Reply

Join Date: Aug 2007
Posts: 14
Reputation: w32.sysfile is an unknown quantity at this point 
Solved Threads: 0
w32.sysfile w32.sysfile is offline Offline
Newbie Poster

calling another function in nested class

 
0
  #1
Aug 25th, 2007
this is my code..
  1. class NewAction implements ActionListener
  2. {
  3. public void actionPerformed(ActionEvent e)
  4. {
  5.  
  6. TArea2.setDocument(new PlainDocument());
  7. }
  8. }
  9. void confirmation()
  10. {
  11. int ReturnValue=JOptionPane.showConfirmDialog(null,"Do you want to open a new file? ","Confirmation ", JOptionPane.YES_NO_CANCEL_OPTION );
  12.  
  13. if(ReturnValue==JOptionPane.YES_OPTION)
  14. {
  15. //HOW CAN I POSSIBLY CALL THE METHOD IN THE NewAction class??
  16. }
  17. else if(ReturnValue==JOptionPane.CANCEL_OPTION)
  18. {
  19. }
  20. }


sorry for my newbie question but can we actually call the actionPerformed method inside the NewAction class from the confirmation method??

i did try some like
this.NewAction().actionPerformed();
myclass.NewAction.actionPeformed();
NewAction().actionPerformed();
NewAction.actionPerformed();

i dont know any possibilities anymore..
help me please..
i changed the NewAction class become public but still doesnt work..


thanks
Last edited by w32.sysfile; Aug 25th, 2007 at 6:20 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: calling another function in nested class

 
0
  #2
Aug 25th, 2007
Think about what you're doing:
You want to call a method on a class, so you'd better make sure you have an instance of that class.

In this case that class is an inner class to another class, so you must first have an instance of that other class.

That leads you to something like
  1. this.new NewAction().actionPerformed();
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 14
Reputation: w32.sysfile is an unknown quantity at this point 
Solved Threads: 0
w32.sysfile w32.sysfile is offline Offline
Newbie Poster

Re: calling another function in nested class

 
0
  #3
Aug 25th, 2007
it doesnt work, but thanks

i think it is better to changet the hierarchy, i realize that my code is confusing
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: calling another function in nested class

 
0
  #4
Aug 25th, 2007
well, based on your bit of code something like that should work.
Problem is that that code is rather ambiguous and it is of course not at all clear what you're actually trying to accomplish.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 14
Reputation: w32.sysfile is an unknown quantity at this point 
Solved Threads: 0
w32.sysfile w32.sysfile is offline Offline
Newbie Poster

Re: calling another function in nested class

 
0
  #5
Aug 25th, 2007
ok then, actually i am making a notepad like program, i want whenever i press the "New" , "Open", Exit" buttons, it will prompt me for saving, but now i am confused with this..
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,433
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: calling another function in nested class

 
0
  #6
Aug 27th, 2007
You could of course just put that code in a regular method and call it from your other listeners. Why do you feel it needs to be another class?

If it does need to be a class, then yes, you can call it like jwenting wrote, but of course you will need to supply the method parameter. A null will suffice if you aren't actually using the ActionEvent param for anything. If you tried to call it with no parameter then certainly it didn't work.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: calling another function in nested class

 
0
  #7
Aug 28th, 2007
i think u shud try the following:
  1. (new NewAction()).actionPerformed();
just one extra ()
A Perfect World
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC