jadex.micro.tutorial.ChatGuiD3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-micro Show documentation
Show all versions of jadex-applications-micro Show documentation
The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.
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;
}
});
}
});
}
}