Inner class problems

I am working with an example of using inner classes and anonymous inner classes. I thought I was understanding the concept but after struggling for several hours with it, I have found out i don't understand it so well.

I am having trouble figuring out how to access methods in the inner class. From the examples I've been looking at, it seems to be set up right but I'm not sure.

The code I have so far is:

import java.awt.*;

import java.awt.event.*;

import java.applet.Applet;

import java.util.*;

publicclass Applet2extends Applet{

publicvoid init(){

Vector v =new Vector();

final TextArea ta =new TextArea(5,80);

Choice chooser =new Choice();

chooser.addItem("mouseClicked");

chooser.addItem("mouseEntered");

chooser.addItem("mouseExited");

chooser.addItem("mousePressed");

chooser.addItem("mouseReleased");

chooser.addItemListener(new ItemListener(){

publicvoid itemStateChanged(ItemEvent e){

System.out.println(MouseClicked.toString() +" was selected");

ta.append("clicked");

}

});

add(ta);

add(chooser);

class MouseClickedextends MouseAdapter{

publicvoid mouseClicked(MouseEvent e){

System.out.println("Mouse click was selected");

}

public String toString(){

return ("mouseClicked");}

}

}}

I get an error on the line MouseClicked.toString()

that says

MouseClicked cannot be resolved. If I understand the error message, it means that it can't find the inner class called MouseClicked. That would make since because in an earlier attempt I tried to create an instance of the MouseClicked class and received the same error.

I'm not sure exactly what question to ask because I don't where the problem lies right now. I have wondered a few things like ,can I not call a method in an inner class from another inner class, but I don't know of any reason why you wouldn't be able to.

Any help at all would be appreciated.

[3405 byte] By [FreddieFrooa] at [2007-10-2 12:42:55]
# 1
Put your MouseClicked inner class outside the init() method and inside the Applet2 class.Regards
jfbrierea at 2007-7-13 9:48:59 > top of Java-index,Java Essentials,New To Java...
# 2

> Put your MouseClicked inner class outside the

> init() method and inside the Applet2

> class.

Thank you, that fixed it. Also it helps me make since of why I was trying to create an instance of the inner class before.

Thanks again. If you wouldn't have helped me, I was about to move on to something other than inner classes and would have always assumed they were hard to work with and then avoided them altogether.

FreddieFrooa at 2007-7-13 9:48:59 > top of Java-index,Java Essentials,New To Java...