Results 1 to 4 of 4
  1. #1
    smhasan11 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default Swing- How to indentify certain actions from sub-panels..

    Hello everyone,
    I'm new to Swing... and I desperately need help...
    I have ‘n’ numbers of JPanel. And each panel contains certain number of sub-panels. Those sub-panels have actionlisteners. How can I identify which sub-panel fire an action?
    For example –
    Panel_1 => sub_1, sub_2, sub_3
    Panel_2 => sub_1, sub_2, sub_3
    Panel_n => sub_1, sub_2, sub_3
    Note that ‘n’ is unknown and main panels will be created dynamically. Now, if I attach actionListener with all of those sub_panels, how would I be able to figure out which sub_panel fires that action and thatsub-panel belongs to which main panel? In other words, if, sub_2 fires an action, how can I figure out that sub_2 belongs to which main panel?
    Please help me.

  2. #2
    fex
    fex is offline Member
    Join Date
    Dec 2010
    Posts
    20
    Rep Power
    0

    Default

    Hello,

    The easiest way here is to use inheritance. Make your own Panel Class (which possibly extends JPanel) that expresses the commonality of all panels you need. Then each panel you create is an extended class of your own Panel Class. It then has it's own actionListener methods, which prevents the problem you are having now and it keeps your code quite clean.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

Similar Threads

  1. JSP standard actions
    By subhashis_mohanty in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 11-27-2010, 07:35 AM
  2. How to Use Actions
    By AJArmstron@aol.com in forum New To Java
    Replies: 4
    Last Post: 04-18-2010, 09:03 PM
  3. How to indentify Mobile Device ID ?
    By manishbathwal in forum CLDC and MIDP
    Replies: 3
    Last Post: 08-07-2009, 12:16 PM
  4. Button Actions
    By vasavi.singh in forum Advanced Java
    Replies: 3
    Last Post: 04-03-2009, 09:50 PM
  5. Actions
    By alley in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2008, 02:52 PM

Posting Permissions

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