Results 1 to 3 of 3
- 02-21-2011, 07:44 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
How to enable MenuItem Onclicking handeling in this case
Hi, I'm programming to solve a 3X3 Rubik's Cube using Evolutionary Algorithm.
Finally I reach GUI, but I encounter a problem here.
What I want to do is manually initialising a Cube (make it crambled ) and solve it by clicking the MenuItem. But the ActionListeners are added in the test Class which extends Frame while the methods of changing the state of the Cube is AnimCube which extends Panel in the Class. How can I manage it?
Thanks a lot!
My structure of program:
Java Code:public class test extends Frame implements ActionListener { public static void main(String[] args) {new test();} test() { super("Rubik's Cube"); MenuBar mb; Menu m1; MenuItem mi1_1,mi1_2,mi1_3; addWindowListener(new WindowAdapter() {public void windowClosing( WindowEvent e){System.exit(0);}}); //Build the menu bar mb = new MenuBar(); setMenuBar(mb); //Build menus in the menu bar m1 = new Menu("Menu 1"); mb.add(m1); mi1_1 = new MenuItem("initialise"); m1.add(mi1_1); mi1_2 = new MenuItem("solve"); m1.add(mi1_2); mi1_3 = new MenuItem("back"); m1.add(mi1_3); m1.addActionListener(this); setSize(600,500); add("Center",new AnimCube()); setVisible(true); } /** * This class deals with solving a scrambled Cube, 3d-projections .. */ class AnimCube extends Panel implements Runnable, MouseListener, MouseMotionListener { public void paint(Graphics g) { ..... } public void mouseExited(MouseEvent e) { ..... } }Last edited by Coiby; 02-21-2011 at 07:47 AM.
- 02-21-2011, 10:57 AM #2
Member
- Join Date
- Jan 2011
- Location
- India
- Posts
- 22
- Rep Power
- 0
You can add ActionListener in any class "this" keyword is user to refer current class objects..
and also implement ActionListener interface and it's abstract methods...! in AnimCube classJava Code:AnimCube obj=new AnimCube(); menuitem.addActionListener(obj); setSize(600,500); add("Center",obj);
- 02-21-2011, 11:25 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
textfield on a menuitem
By cotarelo in forum AWT / SwingReplies: 1Last Post: 06-29-2010, 04:11 PM -
empty menuItem in the menu
By anix in forum New To JavaReplies: 8Last Post: 06-08-2010, 06:59 PM -
[SOLVED] Dynamic String -> Date Handeling
By vagetoanima in forum Advanced JavaReplies: 2Last Post: 03-31-2009, 06:43 PM -
various actions in menuitem of popupmenu
By Peggy in forum Java AppletsReplies: 0Last Post: 12-11-2008, 11:50 AM -
MenuItem
By Sarinam in forum New To JavaReplies: 1Last Post: 07-15-2008, 10:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks