jadex.bdi.examples.booktrading.common.Gui Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
package jadex.bdi.examples.booktrading.common;
import jadex.bdi.runtime.AgentEvent;
import jadex.bdi.runtime.IAgentListener;
import jadex.bdi.runtime.IBDIExternalAccess;
import jadex.commons.SGUI;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
* The gui allows to add and delete buy or sell orders and shows open and
* finished orders.
*/
public class Gui extends JFrame
{
//-------- constructors --------
/**
* Shows the gui, and updates it when beliefs change.
*/
public Gui(final IBDIExternalAccess agent)//, final boolean buy)
{
super((GuiPanel.isBuyer(agent)? "Buyer: ": "Seller: ")+agent.getComponentName());
GuiPanel gp = new GuiPanel(agent);
agent.addAgentListener(new IAgentListener()
{
public void agentTerminating(AgentEvent ae)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
dispose();
}
});
}
public void agentTerminated(AgentEvent ae)
{
}
});
// gp.refresh();
add(gp, BorderLayout.CENTER);
pack();
setLocation(SGUI.calculateMiddlePosition(this));
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
agent.killAgent();
}
});
}
}