Package ds.ihm.gui.launch

Source Code of ds.ihm.gui.launch.PanelChoix

package ds.ihm.gui.launch;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;

import ds.ihm.Ihm;
import ds.ihm.joystick.ConfigurationJoystick;
import ds.io.FileLoadeur;

@SuppressWarnings("serial")
public class PanelChoix extends JPanel implements ActionListener {
 
  private final static Dimension DIMENSION = new Dimension(300, 80);

  private Ihm ihm;
  private FileLoadeur fl;
 
  private JComboBox comboTerrain;
  private JCheckBox checkBoxJoystick;
  private JButton lancer;
 
  public PanelChoix(Ihm ihm){
    super();
    this.ihm = ihm;
  }
 
  public void init(boolean joystickActif){
    this.setLayout(null);
    this.setPreferredSize(DIMENSION);
   
    fl = new FileLoadeur();
    fl.init();
   
    this.comboTerrain = new JComboBox();
    this.comboTerrain.setBounds(10, 10, 140, 20);
    this.comboTerrain.setModel(new DefaultComboBoxModel(fl.getNomsTerrain().toArray()));
    this.add(comboTerrain);
   
    this.checkBoxJoystick = new JCheckBox("Activer Joystick");
    this.checkBoxJoystick.setBounds(160, 10, 140, 20);
    this.checkBoxJoystick.setSelected(joystickActif);
    this.add(checkBoxJoystick);
   
    this.lancer = new JButton("Lancer");
    this.lancer.setBounds(110, 40, 80, 30);
    this.lancer.addActionListener(this);
    this.add(lancer);
  }

  public void actionPerformed(ActionEvent event) {
    if(event.getSource().equals(this.lancer)){
      ConfigurationJoystick confJoy = this.ihm.getGestionnaireJoystick().getConfJoystick();
      confJoy.setUtiliserJoystick(this.checkBoxJoystick.isSelected());
      try {
        confJoy.saveConf();
      } catch (IOException e) {
        System.out.println("Impossible de sauvegarder la configuration joystick");
      }
      int indexFichier = this.comboTerrain.getSelectedIndex();
      this.ihm.getControleur().initSimu(fl.getFichiersTerrain().get(indexFichier));
    }
  }
}
TOP

Related Classes of ds.ihm.gui.launch.PanelChoix

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.