943,547 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4294
  • Java RSS
Aug 25th, 2007
0

calling another function in nested class

Expand Post »
this is my code..
Java Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
w32.sysfile is offline Offline
14 posts
since Aug 2007
Aug 25th, 2007
0

Re: calling another function in nested class

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
Java Syntax (Toggle Plain Text)
  1. this.new NewAction().actionPerformed();
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Aug 25th, 2007
0

Re: calling another function in nested class

it doesnt work, but thanks

i think it is better to changet the hierarchy, i realize that my code is confusing
Reputation Points: 9
Solved Threads: 0
Newbie Poster
w32.sysfile is offline Offline
14 posts
since Aug 2007
Aug 25th, 2007
0

Re: calling another function in nested class

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Aug 25th, 2007
0

Re: calling another function in nested class

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..
Reputation Points: 9
Solved Threads: 0
Newbie Poster
w32.sysfile is offline Offline
14 posts
since Aug 2007
Aug 27th, 2007
0

Re: calling another function in nested class

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Aug 28th, 2007
0

Re: calling another function in nested class

i think u shud try the following:
java Syntax (Toggle Plain Text)
  1. (new NewAction()).actionPerformed();
just one extra ()
Reputation Points: 46
Solved Threads: 11
Junior Poster
orko is offline Offline
164 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to
Next Thread in Java Forum Timeline: convert string to double, and result is string again





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC