this is my code..

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

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

this.new NewAction().actionPerformed();

it doesnt work, but thanks

i think it is better to changet the hierarchy, i realize that my code is confusing

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.

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

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.

i think u shud try the following:

(new NewAction()).actionPerformed();

just one extra () :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.