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

jadex.micro.tutorial.ChatGuiD3 Maven / Gradle / Ivy

Go to download

The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.

There is a newer version: 4.0.267
Show newest version
package jadex.micro.tutorial;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JPanel;

import jadex.bridge.IComponentStep;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.IFuture;

/**
 *  The chat gui with profile button.
 */
public class ChatGuiD3 extends ChatGuiD2
{
	/**
	 *  Create the user interface
	 */
	public ChatGuiD3(final IExternalAccess agent)
	{
		super(agent);
		JButton profiles = new JButton("Profiles");
		JPanel p = new JPanel();//new BorderLayout());
		p.add(profiles);//, BorderLayout.CENTER);
		getContentPane().add(p, BorderLayout.NORTH);
		profiles.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				agent.scheduleStep(new IComponentStep()
				{
					public IFuture execute(IInternalAccess ia)
					{
						IFuture>	chatservices	= ia.getComponentFeature(IRequiredServicesFeature.class).getRequiredServices("chatservices");
						chatservices.addResultListener(new DefaultResultListener>()
						{
							public void resultAvailable(Collection result)
							{
								for(Iterator it=result.iterator(); it.hasNext(); )
								{
									IExtendedChatService cs = it.next();
									cs.getUserProfile().addResultListener(new DefaultResultListener()
									{
										public void resultAvailable(UserProfileD3 result)
										{
											addMessage(result.toString());
										}
									});
								}
							}
						});
						return IFuture.DONE;
					}
				});
			}
		});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy