Merge branch 'zhouhao_branch'
This commit is contained in:
commit
e2dc6a6019
|
@ -32,14 +32,17 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
private RobotSelectionPanel robotSelectionPanel;
|
||||
private TeamCreatorOptionsPanel teamCreatorOptionsPanel;
|
||||
|
||||
private final int minRobots = 2;
|
||||
private final int maxRobots = 10;
|
||||
private final int minRobots = 2;//每个编队至少两人
|
||||
private final int maxRobots = 10;//每个编队最多10人
|
||||
|
||||
private final EventHandler eventHandler = new EventHandler();
|
||||
|
||||
//EventHandler具体实现ActionListener接口,实现动作的监听操作
|
||||
class EventHandler implements ActionListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//e为传入的参数,传入临时变量e,为ActionEvent类型
|
||||
if (e.getActionCommand().equals("Refresh")) {
|
||||
//执行跟新操作
|
||||
getRobotSelectionPanel().refreshRobotList(true);
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +63,12 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
return teamCreatorOptionsPanel;
|
||||
}
|
||||
|
||||
//获取创建编队嵌入框中的内容
|
||||
private JPanel getTeamCreatorContentPane() {
|
||||
if (teamCreatorContentPane == null) {
|
||||
//如果嵌入框内容为空
|
||||
teamCreatorContentPane = new JPanel();
|
||||
//新建嵌入框
|
||||
teamCreatorContentPane.setLayout(new BorderLayout());
|
||||
teamCreatorContentPane.add(getWizardController(), BorderLayout.SOUTH);
|
||||
teamCreatorContentPane.add(getWizardPanel(), BorderLayout.CENTER);
|
||||
|
@ -76,8 +82,12 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
return teamCreatorContentPane;
|
||||
}
|
||||
|
||||
protected RobotSelectionPanel getRobotSelectionPanel() {
|
||||
if (robotSelectionPanel == null) {
|
||||
//选择机器人组成编队
|
||||
protected RobotSelectionPanel getRobotSelectionPanel()
|
||||
{
|
||||
//如果当前选择为空
|
||||
if (robotSelectionPanel == null)
|
||||
{
|
||||
robotSelectionPanel = net.sf.robocode.core.Container.createComponent(RobotSelectionPanel.class);
|
||||
robotSelectionPanel.setup(minRobots, maxRobots, false, "Select the robots for this team.", false, true, true,
|
||||
false, false, false, null);
|
||||
|
@ -85,8 +95,10 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
return robotSelectionPanel;
|
||||
}
|
||||
|
||||
private WizardCardPanel getWizardPanel() {
|
||||
if (wizardPanel == null) {
|
||||
private WizardCardPanel getWizardPanel()
|
||||
{
|
||||
if (wizardPanel == null)
|
||||
{
|
||||
wizardPanel = new WizardCardPanel(this);
|
||||
wizardPanel.add(getRobotSelectionPanel(), "Select robots");
|
||||
wizardPanel.add(getTeamCreatorOptionsPanel(), "Select options");
|
||||
|
@ -94,23 +106,27 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
return wizardPanel;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
//窗口初始化
|
||||
public void initialize()
|
||||
{
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle("Create a team");
|
||||
setContentPane(getTeamCreatorContentPane());
|
||||
}
|
||||
|
||||
private WizardController getWizardController() {
|
||||
if (wizardController == null) {
|
||||
if (wizardController == null)
|
||||
{
|
||||
wizardController = getWizardPanel().getWizardController();
|
||||
}
|
||||
return wizardController;
|
||||
}
|
||||
|
||||
//添加取消键动作
|
||||
public void cancelButtonActionPerformed() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
//添加完成键动作
|
||||
public void finishButtonActionPerformed() {
|
||||
try {
|
||||
int rc = createTeam();
|
||||
|
@ -128,12 +144,14 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
}
|
||||
}
|
||||
|
||||
//将创建的编队写入数据库
|
||||
public int createTeam() throws IOException {
|
||||
File file = new File(repositoryManager.getRobotsDirectory(),
|
||||
teamCreatorOptionsPanel.getTeamPackage().replace('.', File.separatorChar)
|
||||
+ teamCreatorOptionsPanel.getTeamNameField().getText() + ".team");
|
||||
|
||||
if (file.exists()) {
|
||||
//如果当前编队已经存在
|
||||
int ok = JOptionPane.showConfirmDialog(this, file + " already exists. Are you sure you want to replace it?",
|
||||
"Warning", JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
|
||||
|
@ -151,10 +169,13 @@ public class TeamCreator extends JDialog implements WizardListener {
|
|||
String webPageFieldString = teamCreatorOptionsPanel.getWebpageField().getText();
|
||||
|
||||
if (webPageFieldString != null && webPageFieldString.length() > 0) {
|
||||
try {
|
||||
try
|
||||
{
|
||||
webPageUrl = new URL(webPageFieldString);
|
||||
} catch (MalformedURLException e) {
|
||||
try {
|
||||
} catch (MalformedURLException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
webPageUrl = new URL("http://" + webPageFieldString);
|
||||
teamCreatorOptionsPanel.getWebpageField().setText(webPageUrl.toString());
|
||||
} catch (MalformedURLException ignored) {}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue