“Firstly, add ActionListeners to each of the JMenuItem objects. For
example, when you select “Square” from the menu, the ActionListener
attached to the ‘Square’ menu item must create an instance of your
‘Square’ class. These ActionListeners will be added as code within the
constructor of your MyFrame class.”
Could someone please walk me through how to do this?
Once the square is selected i need to then use my Jslider to some how work the area of the square, (given that the jslider value is one side of the square)
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.htmlThen 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, youractionPerformed()method would do something like this…You would need to add additional
if-elsestatements for the different menu items.Finally, it says that you need to add the
ActionListeners to yourMyFrameclass, so it should be something like this…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.