package gui.ex04_independentGUI;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JPanel;

import gui.ex03_customPanel.CustomPanel;
import madkit.gui.OutputPanel;
import madkit.kernel.Agent;
import madkit.kernel.Madkit;

 * Shows how to build a totally independent GUI for an agent.
 * Not using the default GUI mechanism of course makes the source code much more longer without any real benefits here.
 * So, it is safe to say that the default mechanism should be used almost always. This because: (1) the default
 * mechanism does not prevent a full control over the created frame. (2) the life cycle of the agent is automatically
 * related with the frame's, so that nothing has to be added. Still, there are of course cases where it could be a
 * convenient solution. Especially, it could be interesting to use both the default mechanism and an independent GUI for
 * developing/debugging purposes like in the next example.

public class IndependentGUI extends Agent {

    private JFrame myFrame;

     * building my own GUI here
    protected void activate() {
       myFrame = new JFrame("My own title");

       JPanel p = new JPanel(new BorderLayout());

       JPanel talkPanel = new OutputPanel(this);
       p.add(talkPanel, BorderLayout.CENTER);

       p.add(new JLabel(new ImageIcon(CustomPanel.class.getResource("agent.png"))), BorderLayout.NORTH);

       // but still getting some help from madkit.gui components
       JMenuBar menuBar = new JMenuBar();
       menuBar.add(new AgentMenu(this));
       menuBar.add(new AgentLogLevelMenu(this));

       myFrame.setSize(400, 500);
       myFrame.setLocationRelativeTo(null);// centered

       // Beware that end will not be called
       // if the frame is closed by the user...


    protected void live() {
       getLogger().info("\n\tI have defined my own frame,\n\twith some predefined menus, though");

     * I have to close the frame myself because its life cycle is not managed by the MaDKit kernel.
    protected void end() {


     * @param argss
     *            unused here
    public static void main(String[] argss) {
       String[] args = { "--launchAgents", IndependentGUI.class.getName() };
       // + ",false" }; would not change anything as it is the default setting