Package jade.gui

Class GuiAgent

  • All Implemented Interfaces:
    TimerListener, Serializable, Serializable, Runnable
    Direct Known Subclasses:
    df

    public abstract class GuiAgent
    extends Agent
    When a program instantiates a GUI, the Java programming language starts a new thread, different from the Agent thread. The Agent thread generally is active because it has its tasks to perform and also the GUI thread is active, in respect to the Agent thread, because its behaviour depends on the user actions (e.g. pressing a button, using the nemu bar,...) and not only on the agent task. Therefore, an appropriate mechanism is needed to manage the interaction between these two active threads. It is not a good practice allowing one thread to just call the method of another thread because of the difference in the thread space. What should be done, instead is one thread requesting the other to execute a method, each thread in its one execution space. Since its common to have an agent with a GUI, this class is for this purpose. This class extends the jade.core.Agent class: at the start-up it instantiate ad ad-hoc behaviour that manages a queue of jade.gui.GuiEvent,event objects that can be received by other threads. A thread (in particular a GUI)to notify an event to an Agent should create a new Object of type jade.gui.GuiEventand pass it as a parameter to the call of the method postGuiEvent of the jade.gui.GuiAgent object. Notice that an object of type GuiEvent has two mandatory attributes and an optional list of parameters that can be added to the event object. After the method postGuiEvent is called,the agent reacts by waking up all its active behaviours, and in particular the one that causes the Agent thread to execute the method onGuiEvent.
    Version:
    $Date$ $Revision$
    Author:
    Giovanni Caire - CSELT S.p.A.
    See Also:
    Agent, GuiEvent, Serialized Form
    • Constructor Detail

      • GuiAgent

        public GuiAgent()
        Default constructor.
    • Method Detail

      • postGuiEvent

        public void postGuiEvent​(GuiEvent e)
        Posts an event from the GUI thread to the agent event queue.
        Parameters:
        e - The GUI event to post.
      • onGuiEvent

        protected abstract void onGuiEvent​(GuiEvent ev)
        Abstract method to handle posted GUI events. Subclasses of GuiAgent will implement their own reactions to GUI events starting with this method.
        Parameters:
        ev - The GUI event to handle.