| | |
calling another function in nested class
![]() |
•
•
Join Date: Aug 2007
Posts: 14
Reputation:
Solved Threads: 0
this is my code..
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
Java Syntax (Toggle Plain Text)
class NewAction implements ActionListener { public void actionPerformed(ActionEvent e) { TArea2.setDocument(new PlainDocument()); } } void confirmation() { int ReturnValue=JOptionPane.showConfirmDialog(null,"Do you want to open a new file? ","Confirmation ", JOptionPane.YES_NO_CANCEL_OPTION ); if(ReturnValue==JOptionPane.YES_OPTION) { //HOW CAN I POSSIBLY CALL THE METHOD IN THE NewAction class?? } else if(ReturnValue==JOptionPane.CANCEL_OPTION) { } }
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.
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
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)
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.
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.
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.
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.
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.
•
•
Join Date: Apr 2006
Posts: 164
Reputation:
Solved Threads: 10
i think u shud try the following:
just one extra ()
java Syntax (Toggle Plain Text)
(new NewAction()).actionPerformed();
A Perfect World
![]() |
Similar Threads
- Can anyone help me understand function polymorphism ? (C++)
- Adding user and mailbox in Active Directory (Python)
- Helping with calling a function (C)
- initializer list err (C++)
- Calling C function from MATLAB (C)
- No matching function (C++)
- Help with calling class members (C++)
- Calling function in a child window from main parent window (C#)
- HELP: class static function - compile errors (C++)
- Still need info on calling a function from bool! (C++)
Other Threads in the Java Forum
- Previous Thread: How to
- Next Thread: convert string to double, and result is string again
| Thread Tools | Search this Thread |
6 actuate add android applet application applications array automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational equation error event file formatingtextintooltipjava fractal froglogic functiontesting game givemetehcodez graphics gui health html hyper idea ideas image infinite ingres int intersect invokingapacheantprogrammatically j2me java javaexcel javame javaprojects jni jpanel jtextarea julia linux main map method mobile myregfun mysql netbeans nextline openjavafx parameter pearl php problem program repositories scanner scrollbar sell server set sms spamblocker sql sqlserver storm sun superclass swing swt thread threads tree websites windows






