Results 1 to 3 of 3
  1. #1
    Coiby is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

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

  2. #2
    Dinesh_rockz is offline Member
    Join Date
    Jan 2011
    Location
    India
    Posts
    22
    Rep Power
    0

    Default

    You can add ActionListener in any class "this" keyword is user to refer current class objects..

    Java Code:
    AnimCube obj=new AnimCube();
    menuitem.addActionListener(obj);
    setSize(600,500);
    add("Center",obj);
    and also implement ActionListener interface and it's abstract methods...! in AnimCube class

  3. #3
    Coiby is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

Similar Threads

  1. textfield on a menuitem
    By cotarelo in forum AWT / Swing
    Replies: 1
    Last Post: 06-29-2010, 04:11 PM
  2. empty menuItem in the menu
    By anix in forum New To Java
    Replies: 8
    Last Post: 06-08-2010, 06:59 PM
  3. [SOLVED] Dynamic String -> Date Handeling
    By vagetoanima in forum Advanced Java
    Replies: 2
    Last Post: 03-31-2009, 06:43 PM
  4. various actions in menuitem of popupmenu
    By Peggy in forum Java Applets
    Replies: 0
    Last Post: 12-11-2008, 11:50 AM
  5. MenuItem
    By Sarinam in forum New To Java
    Replies: 1
    Last Post: 07-15-2008, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •