周浩 8月18日 完善ui中TeamCreator代码

This commit is contained in:
zhoudaxia 2016-08-18 22:31:22 +08:00
parent ecdbf0829d
commit 6471effdae
1 changed files with 24 additions and 9 deletions

View File

@ -37,9 +37,12 @@ public class TeamCreator extends JDialog implements WizardListener {
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);
@ -77,9 +83,11 @@ public class TeamCreator extends JDialog implements WizardListener {
}
//选择机器人组成编队
protected RobotSelectionPanel getRobotSelectionPanel() {
protected RobotSelectionPanel getRobotSelectionPanel()
{
//如果当前选择为空
if (robotSelectionPanel == null) {
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);
@ -87,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");
@ -97,14 +107,16 @@ public class TeamCreator extends JDialog implements WizardListener {
}
//窗口初始化
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;
@ -157,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) {}