DealerFrame.java

package jadex.examples.blackjack.dealer;

import jadex.examples.blackjack.*;
import jadex.examples.blackjack.gui.*;
import jadex.runtime.AgentEvent;
import jadex.runtime.IAgentListener;
import jadex.runtime.IExternalAccess;
import jadex.util.*;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import javax.swing.*;

/**
* This GUI gives an overview of the ongoings during the game.
* It shows different panels representing the 'internal states'
* (the cards, accounts and bets) of the dealer- and all the
* player-agents as well as one special panel containing a
* progressBar and a few buttons (the 'OptionPanel').
* But this class is not just a viewing-component, but also an
* agent-plan and therefor it contains some jadex-specific code,
* which is perhaps worth looking at.
*/
public class DealerFrame extends GameStateFrame
{
//-------- attributes --------

/** The agent access object. */
protected IExternalAccess agent;

/** child windows (e.g. statistics). */
protected Set children;

//-------- constructors --------

/**
* Creates a new instance of the dealer frame.
* Here, the GUI is build up for the first time, all
* panels are instantiated and shown on the screen.
*/
public DealerFrame(final Dealer me, final IExternalAccess agent)
{
super(null, null);
this.agent = agent;
this.children = new HashSet();

// Show Jadex version information.
String title = "Blackjack Dealer";
//+ Configuration.getConfiguration().getReleaseNumber()
//+ " (" + Configuration.getConfiguration().getReleaseDate() + ")";

//Create the 'Main'-Window and the contentPane
setTitle(title);
//setResizable(false);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
DealerFrame.this.agent.killAgent();
}
});
agent.addAgentListener(new IAgentListener()
{
public void agentTerminating(AgentEvent ae)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
DealerFrame.this.dispose();
}
});
}
}, false);

// set the icon to be displayed for the frame
setIconImage(GUIImageLoader.getImage("heart_small_d").getImage());

SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
DealerFrame.this.setGameState((GameState)agent.getBeliefbase().getBelief("gamestate").getFact());
}
});
setControlPanel(new DealerOptionPanel(agent, DealerFrame.this));

/*getContentPane().setLayout(new GridLayout(0, 2));

// initialise the JPanels for the Dealer and the progressBar
PlayerPanel dealerPanel = new PlayerPanel(me);

// add these JPanels as the first-row to the contentPane
getContentPane().add(dealerPanel);
getContentPane().add(new DealerOptionPanel(agent, DealerFrame.this));*/

// display the gui on the screen
pack();
setLocation(SGUI.calculateMiddlePosition(DealerFrame.this));
setVisible(true);
}

/**
* Add a child window to be disposed on exit.
*/
public void addChildWindow(Window child)
{
children.add(child);
}

/**
* Remove a child window to be disposed on exit.
*/
public void removeChildWindow(Window child)
{
children.remove(child);
}

/**
* Dispose this window and child windows.
*/
public void dispose()
{
super.dispose();

for(Iterator i=children.iterator(); i.hasNext(); )
((Window)i.next()).dispose();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值