F01_Zombie/src/graphique/MaJFrame.java

377 lines
13 KiB
Java

package graphique;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.FormSpecs;
import java.awt.GridLayout;
import java.awt.Image;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import net.miginfocom.swing.MigLayout;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import javax.swing.border.BevelBorder;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Window.Type;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.JProgressBar;
import java.awt.CardLayout;
import javax.swing.JLayeredPane;
import javax.swing.border.CompoundBorder;
public class MaJFrame extends JFrame {
private JPanel contentPane;
private static final long serialVersionUID = 7252959164975426293L;
private JPanel panelBoutonJouer;
private JPanel panelEnsemble;
private JLabel lblZombicide;
private JPanel panelInfo;
private JButton btnDeplacer;
private JButton btnAttaquer;
private JSpinner deplacementX;
private JSpinner deplacementY;
private JLabel lblDepX;
private JLabel lblDepY;
private JLabel lblScore;
private JPanel panelScore;
private JLabel lblScoreVie;
private JLabel lblAttaque;
private JProgressBar progressBarVie;
private JProgressBar progressBarAttaque;
private JPanelImage panelMap;
private JPanelDessin panelGrille;
private ImageIcon joueurIcon;
private JLabel lblJoueur;
private JLabel lblNbZombiesTues;
private JLabel lblNbZombies;
// private Simulateur sim;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MaJFrame frame = new MaJFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws IOException
*/
public MaJFrame() throws IOException {
setIconImage(Toolkit.getDefaultToolkit().getImage(MaJFrame.class.getResource("/images/zombie.png")));
// création et variable contentPane
setTitle("Zombicide");
setBackground(new Color(128, 0, 0));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1008, 886);
contentPane = new JPanel();
contentPane.setBackground(new Color(128, 0, 0));
contentPane.setBorder(new EmptyBorder(2, 2, 2, 2));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
//création panel bouton Jouer
panelBoutonJouer = new JPanel();
panelBoutonJouer.setBorder(null);
panelBoutonJouer.setBackground(new Color(64, 0, 0));
contentPane.add(panelBoutonJouer); //, "cell 10 10,grow"
contentPane.add(panelBoutonJouer, BorderLayout.NORTH);
panelBoutonJouer.setLayout(new BorderLayout(0, 0));
JButton btnJouer = new JButton("JOUER !");
btnJouer.setForeground(new Color(255, 255, 255));
btnJouer.setBackground(new Color(255, 128, 0));
btnJouer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clicBoutonJouer();
}
});
panelBoutonJouer.add(btnJouer);
//création panelEnsemble contient panelMap et panelInofo
panelEnsemble = new JPanel();
panelEnsemble.setBorder(null);
contentPane.add(panelEnsemble, BorderLayout.CENTER);
GridBagLayout gbl_panelEnsemble = new GridBagLayout();
gbl_panelEnsemble.columnWidths = new int[] {835, 66, 75};
gbl_panelEnsemble.rowHeights = new int[]{789, 0};
gbl_panelEnsemble.columnWeights = new double[]{0.0, 0.0, 0.0};
gbl_panelEnsemble.rowWeights = new double[]{0.0, Double.MIN_VALUE};
panelEnsemble.setLayout(gbl_panelEnsemble);
//création panel Map
panelMap = new JPanelImage("map1.png");
GridBagConstraints gbc_panelMap = new GridBagConstraints();
gbc_panelMap.insets = new Insets(0, 0, 18, 5);
gbc_panelMap.fill = GridBagConstraints.BOTH;
gbc_panelMap.gridx = 0;
gbc_panelMap.gridy = 0;
panelEnsemble.add(panelMap, gbc_panelMap);
panelMap.setLayout(new CardLayout(0, 0));
//création panel Grille
panelGrille = new JPanelDessin();
panelGrille.setBackground(null);
panelGrille.setForeground(new Color(235, 235, 235));
panelGrille.setOpaque(false);
panelMap.add(panelGrille, "panelGrille");
GridBagLayout gbl_panelGrille = new GridBagLayout();
gbl_panelGrille.columnWidths = new int[] {75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75};
gbl_panelGrille.rowHeights = new int[] {71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71};
gbl_panelGrille.columnWeights = new double[]{0.0};
gbl_panelGrille.rowWeights = new double[]{0.0};
panelGrille.setLayout(gbl_panelGrille);
//ajout joueur
lblJoueur = new JLabel();
lblJoueur.setForeground(new Color(255, 128, 0));
//joueurIcon = new ImageIcon("joueur.png");
lblJoueur.setIcon(new ImageIcon(MaJFrame.class.getResource("/images/joueur.png")));
GridBagConstraints gbc_joueur = new GridBagConstraints();
gbc_joueur.fill = GridBagConstraints.CENTER;
gbc_joueur.gridx = 2;
gbc_joueur.gridy = 4;
gbc_joueur.gridwidth = 1; // Occupy 1 column
gbc_joueur.gridheight = 1; // Occupy 1 row
gbc_joueur.anchor = GridBagConstraints.CENTER;
panelGrille.add(lblJoueur, gbc_joueur);
lblZombicide = new JLabel("ZOMBICIDE");
lblZombicide.setFont(new Font("Tahoma", Font.BOLD, 40));
lblZombicide.setForeground(new Color(255, 128, 0));
lblZombicide.setHorizontalAlignment(SwingConstants.CENTER);
panelMap.add(lblZombicide, "lblZombicide");
lblZombicide.setVisible(true);
// création panelInfo
panelInfo = new JPanel();
panelInfo.setBackground(new Color(95, 95, 95));
GridBagConstraints gbc_panelInfo = new GridBagConstraints();
gbc_panelInfo.fill = GridBagConstraints.BOTH;
gbc_panelInfo.gridx = 2;
gbc_panelInfo.gridy = 0;
panelEnsemble.add(panelInfo, gbc_panelInfo);
GridBagLayout gbl_panelInfo = new GridBagLayout();
gbl_panelInfo.columnWidths = new int[] {75};
gbl_panelInfo.rowHeights = new int[] {20, 190, 56, 87, 91, 82, 30, 30, 30, 55, 91, 0};
gbl_panelInfo.columnWeights = new double[]{1.0};
gbl_panelInfo.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panelInfo.setLayout(gbl_panelInfo);
lblScore = new JLabel("Scores");
lblScore.setForeground(new Color(240, 240, 240));
lblScore.setHorizontalAlignment(SwingConstants.CENTER);
lblScore.setVerticalAlignment(SwingConstants.BOTTOM);
GridBagConstraints gbc_lblScore = new GridBagConstraints();
gbc_lblScore.insets = new Insets(0, 0, 5, 0);
gbc_lblScore.gridx = 0;
gbc_lblScore.gridy = 0;
panelInfo.add(lblScore, gbc_lblScore);
btnDeplacer = new JButton("Déplacer");
btnDeplacer.setIcon(null);
btnDeplacer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
panelScore = new JPanel();
panelScore.setBackground(new Color(95, 95, 95));
GridBagConstraints gbc_panelScore = new GridBagConstraints();
gbc_panelScore.anchor = GridBagConstraints.NORTH;
gbc_panelScore.insets = new Insets(0, 0, 5, 0);
gbc_panelScore.gridx = 0;
gbc_panelScore.gridy = 1;
panelInfo.add(panelScore, gbc_panelScore);
GridBagLayout gbl_panelScore = new GridBagLayout();
gbl_panelScore.columnWidths = new int[] {30, 10};
gbl_panelScore.rowHeights = new int[] {30, 90, 0};
gbl_panelScore.columnWeights = new double[]{1.0, 0.0};
gbl_panelScore.rowWeights = new double[]{0.0, 0.0, 1.0};
panelScore.setLayout(gbl_panelScore);
lblScoreVie = new JLabel("Vies");
lblScoreVie.setForeground(new Color(240, 240, 240));
lblScoreVie.setVerticalAlignment(SwingConstants.BOTTOM);
GridBagConstraints gbc_lblScoreVie = new GridBagConstraints();
gbc_lblScoreVie.anchor = GridBagConstraints.SOUTH;
gbc_lblScoreVie.insets = new Insets(0, 0, 5, 5);
gbc_lblScoreVie.gridx = 0;
gbc_lblScoreVie.gridy = 0;
panelScore.add(lblScoreVie, gbc_lblScoreVie);
lblAttaque = new JLabel("Attaque");
lblAttaque.setForeground(new Color(240, 240, 240));
lblAttaque.setVerticalAlignment(SwingConstants.BOTTOM);
GridBagConstraints gbc_lblAttaque = new GridBagConstraints();
gbc_lblAttaque.anchor = GridBagConstraints.SOUTH;
gbc_lblAttaque.insets = new Insets(0, 0, 5, 0);
gbc_lblAttaque.gridx = 1;
gbc_lblAttaque.gridy = 0;
panelScore.add(lblAttaque, gbc_lblAttaque);
progressBarVie = new JProgressBar();
progressBarVie.setForeground(new Color(0, 255, 0));
progressBarVie.setValue(4);
progressBarVie.setMaximum(5);
progressBarVie.setOrientation(SwingConstants.VERTICAL);
GridBagConstraints gbc_progressBarVie = new GridBagConstraints();
gbc_progressBarVie.fill = GridBagConstraints.VERTICAL;
gbc_progressBarVie.insets = new Insets(0, 0, 5, 5);
gbc_progressBarVie.gridx = 0;
gbc_progressBarVie.gridy = 1;
panelScore.add(progressBarVie, gbc_progressBarVie);
progressBarAttaque = new JProgressBar();
progressBarAttaque.setForeground(new Color(255, 0, 0));
progressBarAttaque.setValue(3);
progressBarAttaque.setMaximum(5);
progressBarAttaque.setOrientation(SwingConstants.VERTICAL);
GridBagConstraints gbc_progressBarAttaque = new GridBagConstraints();
gbc_progressBarAttaque.insets = new Insets(0, 0, 5, 0);
gbc_progressBarAttaque.fill = GridBagConstraints.VERTICAL;
gbc_progressBarAttaque.gridx = 1;
gbc_progressBarAttaque.gridy = 1;
panelScore.add(progressBarAttaque, gbc_progressBarAttaque);
lblNbZombiesTues = new JLabel(" nombre de zombies tués : ");
lblNbZombiesTues.setForeground(new Color(240, 240, 240));
GridBagConstraints gbc_lblNbZombiesTues = new GridBagConstraints();
gbc_lblNbZombiesTues.anchor = GridBagConstraints.SOUTH;
gbc_lblNbZombiesTues.insets = new Insets(0, 0, 5, 0);
gbc_lblNbZombiesTues.gridx = 0;
gbc_lblNbZombiesTues.gridy = 2;
panelInfo.add(lblNbZombiesTues, gbc_lblNbZombiesTues);
lblNbZombies = new JLabel("x");
lblNbZombies.setForeground(new Color(240, 240, 240));
GridBagConstraints gbc_lblNbZombies = new GridBagConstraints();
gbc_lblNbZombies.anchor = GridBagConstraints.NORTH;
gbc_lblNbZombies.insets = new Insets(0, 0, 5, 0);
gbc_lblNbZombies.gridx = 0;
gbc_lblNbZombies.gridy = 3;
panelInfo.add(lblNbZombies, gbc_lblNbZombies);
//création boutonDeplacer
GridBagConstraints gbc_btnDeplacer = new GridBagConstraints();
gbc_btnDeplacer.fill = GridBagConstraints.BOTH;
gbc_btnDeplacer.insets = new Insets(0, 0, 5, 0);
gbc_btnDeplacer.gridx = 0;
gbc_btnDeplacer.gridy = 4;
panelInfo.add(btnDeplacer, gbc_btnDeplacer);
lblDepX = new JLabel("déplacement X");
lblDepX.setForeground(new Color(240, 240, 240));
lblDepX.setVerticalAlignment(SwingConstants.BOTTOM);
GridBagConstraints gbc_lblDepX = new GridBagConstraints();
gbc_lblDepX.fill = GridBagConstraints.BOTH;
gbc_lblDepX.insets = new Insets(0, 0, 5, 0);
gbc_lblDepX.gridx = 0;
gbc_lblDepX.gridy = 5;
panelInfo.add(lblDepX, gbc_lblDepX);
deplacementX = new JSpinner();
deplacementX.setFont(new Font("Tahoma", Font.PLAIN, 10));
deplacementX.setModel(new SpinnerNumberModel(0, -3, 3, 1));
GridBagConstraints gbc_deplacementX = new GridBagConstraints();
gbc_deplacementX.insets = new Insets(0, 0, 5, 0);
gbc_deplacementX.gridx = 0;
gbc_deplacementX.gridy = 6;
panelInfo.add(deplacementX, gbc_deplacementX);
lblDepY = new JLabel("déplacement Y");
lblDepY.setForeground(new Color(240, 240, 240));
lblDepY.setVerticalAlignment(SwingConstants.BOTTOM);
GridBagConstraints gbc_lblDepY = new GridBagConstraints();
gbc_lblDepY.fill = GridBagConstraints.BOTH;
gbc_lblDepY.insets = new Insets(0, 0, 5, 0);
gbc_lblDepY.gridx = 0;
gbc_lblDepY.gridy = 7;
panelInfo.add(lblDepY, gbc_lblDepY);
deplacementY = new JSpinner();
deplacementY.setFont(new Font("Tahoma", Font.PLAIN, 10));
deplacementY.setModel(new SpinnerNumberModel(0, -3, 3, 1));
GridBagConstraints gbc_deplacementY = new GridBagConstraints();
gbc_deplacementY.insets = new Insets(0, 0, 5, 0);
gbc_deplacementY.gridx = 0;
gbc_deplacementY.gridy = 8;
panelInfo.add(deplacementY, gbc_deplacementY);
//création boutonAttaquer
btnAttaquer = new JButton("Attaquer");
btnAttaquer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
GridBagConstraints gbc_btnAttaquer = new GridBagConstraints();
gbc_btnAttaquer.fill = GridBagConstraints.BOTH;
gbc_btnAttaquer.gridx = 0;
gbc_btnAttaquer.gridy = 10;
panelInfo.add(btnAttaquer, gbc_btnAttaquer);
}
public void clicBoutonJouer() {
lblZombicide.setVisible(false);
lblJoueur.setVisible(true);
}
// protected void clicPause() {
//
// {
//
//
// protected void clicStart () {
// sim = new Simulateur(100,this);
// sim.lancerSimulateur();
//
//
// }
// }
// }
// }
}