All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bdi.examples.shop.CustomerFrame Maven / Gradle / Ivy

Go to download

The Jadex BDI applications package contain several example applications, benchmarks and testcases using BDI agents.

There is a newer version: 2.4
Show newest version
package jadex.bdi.examples.shop;

import jadex.bdi.runtime.IBDIExternalAccess;
import jadex.bdi.runtime.IBDIInternalAccess;
import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.TerminationAdapter;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.commons.gui.SGUI;
import jadex.commons.transformation.annotations.Classname;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

/**
 *  Frame for displaying of the customer gui.
 */
public class CustomerFrame extends JFrame
{
	/**
	 *  Create a new frame.
	 */
	public CustomerFrame(final IBDIExternalAccess agent)
	{
		super(agent.getComponentIdentifier().getName());
		
		add(new CustomerPanel(agent));
		pack();
		setLocation(SGUI.calculateMiddlePosition(this));
		setVisible(true);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
//				agent.killAgent();
				agent.killComponent();
			}
		});
		// Dispose frame on exception.
		IResultListener	dislis	= new IResultListener()
		{
			public void exceptionOccurred(Exception exception)
			{
				dispose();
			}
			public void resultAvailable(Void result)
			{
			}
		};
		agent.scheduleStep(new IComponentStep()
		{
			@Classname("dispose")
			public IFuture execute(IInternalAccess ia)
			{
				IBDIInternalAccess bia = (IBDIInternalAccess)ia;
				bia.addComponentListener(new TerminationAdapter() 
				{
					public void componentTerminated() 
					{
						SwingUtilities.invokeLater(new Runnable()
						{
							public void run()
							{
								setVisible(false);
								dispose();
							}
						});
					}
				});
				return IFuture.DONE;
			}
		}).addResultListener(dislis);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy