Results 1 to 4 of 4
  1. #1
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Question event handling between classes

    I have an issue involving event handling between classes.

    I have a main class that creates a series of panels within a card layout. There are a few buttons that control movement through the cards.

    One of the panels is created from an object created from another class. On this panel are a series of buttons.

    I'd like to be able to click a button on this panel and move a different card (panel).

    Is it possible to access the event handler in the main class from the panel with the button in question created from another class?

    Or must I simply declare the buttons in the main class? (This would make the main class rather cumbersome.)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You probably don't want to declare the buttons in the main class. You might want to look into using an MVC pattern -- Model View Controller -- where the button's actions are part of the Controller class(es).

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    To expand a bit on what Fubarable said... Typically, view components generate events. These components provide some form of addListener() methods so that controller components can create event listeners and add them to the view components. This provides a means for view components to alert controller components when events occur, without the view components having to know anything about the controller components.

    So, all your buttons would be view components. Your view containers must provide a means for the controller components to add event handlers to the individual buttons.
    The Java Tutorial. Read it.

  4. #4
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default Thanks!

    Thanks for the advice, Fubarable and Steve11235. I'll look into it.

Similar Threads

  1. Event handling... help?
    By kevzspeare in forum New To Java
    Replies: 2
    Last Post: 04-04-2009, 08:46 PM
  2. Event handling in JSF
    By java08 in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 03-24-2009, 06:42 AM
  3. rmi and event handling
    By darkhorse in forum Advanced Java
    Replies: 0
    Last Post: 03-15-2009, 08:20 AM
  4. SWT Event Handling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-30-2007, 12:21 PM
  5. Event Handling
    By luisarca in forum Sun Java Wireless Toolkit
    Replies: 5
    Last Post: 05-07-2007, 06:05 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
  •