Seeing as though this looks like homework, I won't give you the specifics, but just a guide...
Following through your instructions, you'll first need to create a class that implements ActionListener
, and implement the 'actionPerformed()' method as described in the documentation at http://docs.oracle.com/javase/6/docs/api/java/awt/event/ActionListener.html
Then you're instructed that this should detect what was clicked, and then create the appropriate Object
. So, as per the Square instruction of your question, your actionPerformed()
method would do something like this...
JMenuItem clickedMenu = (JMenuItem)e.getSource();
if (clickedMenu.getText().equals("Square")){
Square square = new Square();
}
You would need to add additional if-else
statements for the different menu items.
Finally, it says that you need to add the ActionListener
s to your MyFrame
class, so it should be something like this...
JMenuItem menuItem = new JMenuItem("Square");
menuItem.addActionListener(new MyActionListener());
Its just a matter of following through your instructions 1 piece at a time. If you get stuck at any point, try referring to the Java API documentation, or search for help here on StackOverflow.