Package pdp.scrabble.ihm

Source Code of pdp.scrabble.ihm.ChooseModeDialog

package pdp.scrabble.ihm;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JRadioButton;

import pdp.scrabble.Factory;
import pdp.scrabble.game.GameEngine;
import pdp.scrabble.game.GameEnvironment;
import static pdp.scrabble.Language.getGameLang;

/**
*/
public class ChooseModeDialog extends JDialog {
  private static final long serialVersionUID = 1L;

  /** MainFrame reference. */
  private ButtonGroup playMode;
  /** Create a new welcome dialog.
   * @param mainFrame mainFrame reference.
   */
  public ChooseModeDialog() {
    super();
    setTitle("Choix du mode de jeu");
    this.setModal(true);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setResizable(false);
    this.setPreferredSize(new Dimension(320, 190));
    this.setLayout(new BorderLayout());
    this.initialize();
  }

  private void initialize() {
   
    JButton ok = new JButton(String.format(getGameLang("Select")));
    ok.addActionListener(new ActionListener() {
       
        public void actionPerformed(ActionEvent arg0) {
      setVisible(false);
        }
    });
    playMode = new ButtonGroup();
    /*ok.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        playmode.initialize();
        switch(Integer.parseInt(playMode.getSelection().getActionCommand())){
        case 1: playmode.multiRes(); break;
        case 2: playmode.multiLoc(); break;
        case 3: playmode.solo(); break;
        case 4: playmode.simulation(); break;
        case 5: playmode.pedagogique(); break;
        case 6: playmode.charger(); break;
        }
        terminate();
      }
    });*/
    JRadioButton multiRes = new JRadioButton(String.format(getGameLang("Multiplayer Network")));
    multiRes.setActionCommand("Network");
    JRadioButton multiLoc = new JRadioButton(String.format(getGameLang("Multiplayer local")));
    multiLoc.setActionCommand("Local");
    JRadioButton solo = new JRadioButton(String.format(getGameLang("Solo training")));
    solo.setActionCommand("Solo");
    JRadioButton simul = new JRadioButton(String.format(getGameLang("Simulation")));
    simul.setActionCommand("Simulation");
    JRadioButton pedag = new JRadioButton(String.format(getGameLang("learning")));
    pedag.setActionCommand("Learning");
    JRadioButton load = new JRadioButton(String.format(getGameLang("Load Game")));
    load.setActionCommand("Load");
    playMode.add(multiRes);
    playMode.add(multiLoc);
    playMode.add(solo);
    playMode.add(simul);
    playMode.add(pedag);
    playMode.add(load);
   
    JPanel pane =new JPanel();
    BoxLayout mgr= new BoxLayout(pane, BoxLayout.Y_AXIS);
    pane.setLayout(mgr);
    pane.add(multiLoc);
    pane.add(multiRes);
    pane.add(solo);
    pane.add(simul);
    pane.add(pedag);
    pane.add(load);
    pane.add(ok);
    this.add(pane);
   
    /*
     *
     * Old version
    JPanel panel = new JPanel(new BorderLayout());
    this.add(panel, BorderLayout.CENTER);

    JTextPane text = new JTextPane();
    text.setEditable(false);
    text.setText(String.format(getGameLang("Welcome")));
    panel.add(text);

    panel = new JPanel(new GridLayout(0, 2));
    this.add(panel, BorderLayout.SOUTH);

    // New game
    JButton button = new JButton(getGameLang("New Game"));
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        terminate();
        mainFrame.getMenubar().getItem("New Game").doClick();
      }
    });
    panel.add(button);

    // Close
    button = new JButton(getGameLang("Close"));
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        terminate();
      }
    });
    panel.add(button);*/
  }


  /** Start dialog. */
  public void start() {
    this.validate();
    this.pack();
    this.repaint();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
  }
  public static GameEngine mode(GameEnvironment gameEnv, MainFrame mainFrame){
    ChooseModeDialog c= new ChooseModeDialog();
    c.start();
    String mode = c.playMode.getSelection().getActionCommand();
    if(mode.compareTo("load")==0)
      mainFrame.getMenubar().getItem("Load").doClick();
    GameEngine eng = Factory.FACTORY.createEngine(mode, gameEnv);
    return eng;
  }


}
TOP

Related Classes of pdp.scrabble.ihm.ChooseModeDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.