Commit d02d6c03 authored by Hugo DACLON's avatar Hugo DACLON
Browse files

Appli qui marche mieux

parent aa8d9174
......@@ -18,22 +18,27 @@ import java.io.IOException;
import java.util.ArrayList;
public class OptPartie extends JPanel {
// ------Dimensions des boutons------
private final Dimension DIMENSION_RETOUR_MENU = new Dimension(150, 75);
private final Dimension DIMENSION_RETOUR_CREATION = new Dimension(150, 75);
private final Dimension DIMENSION_REFRESH = new Dimension(48, 48);
private final Dimension DIMENSION_JOIN = new Dimension(150, 75);
private final Dimension DIMENSION_HOST = new Dimension(150, 75);
//------Composant généraux------
// ------Composant généraux------
private JButton retourMenu;
private JButton retourCreation;
private JLabel entreePseudoLabel;
//------Composant pour la fenetre CreerPartie------
// ------Composant pour la fenetre CreerPartie------
private JButton hostPartie;
private JPanel boutonCarryHost;
private JTextField choixPseudoHost;
//------Composant pour la fenetre RejoindrePartie------
// ------Composant pour la fenetre RejoindrePartie------
private JButton actualiser;
private JButton joinPartie;
......@@ -45,44 +50,83 @@ public class OptPartie extends JPanel {
private JList<Game> parties;
//------Composant du Panel principal------
// ------Composant du Panel principal------
private JPanel rejoindre;
private JPanel heberger;
private boolean host;
private boolean join;
public OptPartie(String titre, boolean host) {
public OptPartie(String titre) {
this.setName(titre);
//faire une liste des parties initialisées avec le nom dans un label et un bouton rejoindre.
this.setBackground(appli.BACKGROUND_COLOR);
this.host = host;
JPanel principal = new JPanel(new BorderLayout());
JPanel centrage = new JPanel(new BorderLayout());
JPanel[] gap = new JPanel[]{new JPanel(),new JPanel(),new JPanel(),new JPanel(),new JPanel()};
JPanel[] gap = new JPanel[] { new JPanel(), new JPanel(), new JPanel()};
for (JPanel jPanel : gap) {
jPanel.setPreferredSize(new Dimension(20,20));
jPanel.setPreferredSize(new Dimension(20, 20));
}
rejoindre = new JPanel(new BorderLayout());
heberger = new JPanel(new BorderLayout());
host = false;
join = false;
/*------------------------panel rejoindre------------------------*/
//création des boutons
// création des boutons
if (!host) {
try {
retourMenu = new JButton(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonHome1.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourMenu.setRolloverIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonHome1Hover.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourMenu.setPressedIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonHome1Pressed.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourCreation = new JButton(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonRetour1.png")))
.getScaledInstance((int) DIMENSION_RETOUR_CREATION.getWidth(),
(int) DIMENSION_RETOUR_CREATION.getHeight(), Image.SCALE_SMOOTH))));
retourCreation.setRolloverIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonRetour1Hover.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourCreation.setPressedIcon((new ImageIcon(
(ImageIO.read(new File("img/interface/bouton/optPartie/BoutonRetour1Pressed.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
actualiser = new JButton((new ImageIcon(
(ImageIO.read(new File("img/interface/bouton/creationFlotte/BoutonRafraichirMap.png")))
.getScaledInstance((int) DIMENSION_REFRESH.getWidth(),
(int) DIMENSION_REFRESH.getHeight(), Image.SCALE_SMOOTH))));
joinPartie = new JButton(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonTrouver1.png")))
.getScaledInstance((int) DIMENSION_JOIN.getWidth(),
(int) DIMENSION_JOIN.getHeight(), Image.SCALE_SMOOTH))));
joinPartie.setRolloverIcon((new ImageIcon(
(ImageIO.read(new File("img/interface/bouton/optPartie/BoutonTrouver1Hover.png")))
.getScaledInstance((int) DIMENSION_JOIN.getWidth(),
(int) DIMENSION_JOIN.getHeight(), Image.SCALE_SMOOTH))));
joinPartie.setPressedIcon((new ImageIcon(
(ImageIO.read(new File("img/interface/bouton/optPartie/BoutonTrouver1Pressed.png")))
.getScaledInstance((int) DIMENSION_JOIN.getWidth(),
(int) DIMENSION_JOIN.getHeight(), Image.SCALE_SMOOTH))));
} catch (IOException e) {
retourMenu = new JButton("retour");
retourCreation = new JButton("retour à la création de flotte");
actualiser = new JButton((new ImageIcon((ImageIO.read(new File("img/interface/bouton/BoutonRafraichirMap.png"))).getScaledInstance(48,48, Image.SCALE_SMOOTH))));
actualiser.setText("Actualiser");
joinPartie = new JButton("Rejoindre la partie");
} catch (IOException e) {
actualiser = new JButton("Actualiser");
System.out.println("erreur lors du chargement d'une image");
joinPartie = new JButton("Rejoindre la partie");
e.printStackTrace();
}
retourMenu.setPreferredSize(DIMENSION_RETOUR_MENU);
retourCreation.setPreferredSize(DIMENSION_RETOUR_CREATION);
actualiser.setPreferredSize(DIMENSION_REFRESH);
joinPartie.setPreferredSize(DIMENSION_JOIN);
entreePseudoLabel = new JLabel("Entrez votre pseudo : ");
choixPseudoJoin = new JTextField();
......@@ -96,14 +140,17 @@ public class OptPartie extends JPanel {
JPanel PanelWest = new JPanel();
PanelWest.setLayout(new GridLayout(4, 2));
PanelWest.add(entreePseudoLabel); PanelWest.add(choixPseudoJoin);
PanelWest.add(new JPanel()); PanelWest.add(new JPanel());
PanelWest.add(ChercherLabel); PanelWest.add(recherche);
PanelWest.add(new JPanel()); PanelWest.add(new JPanel());
PanelWest.add(entreePseudoLabel);
PanelWest.add(choixPseudoJoin);
PanelWest.add(new JPanel());
PanelWest.add(new JPanel());
PanelWest.add(ChercherLabel);
PanelWest.add(recherche);
PanelWest.add(new JPanel());
PanelWest.add(new JPanel());
centrage.add(PanelWest, BorderLayout.WEST);
boutonCarryJoin = new JPanel();
boutonCarryJoin.setLayout(new BoxLayout(boutonCarryJoin, BoxLayout.X_AXIS));
......@@ -118,42 +165,100 @@ public class OptPartie extends JPanel {
rejoindre.add(boutonCarryJoin, BorderLayout.SOUTH);
JPanel vide = new JPanel();
vide.setPreferredSize(new Dimension(100,100));
vide.setPreferredSize(new Dimension(100, 100));
centrage.add(new JScrollPane(parties), BorderLayout.EAST);
rejoindre.setVisible(false);
rejoindre.add(centrage,BorderLayout.CENTER);
rejoindre.add(vide,BorderLayout.NORTH);
rejoindre.add(vide,BorderLayout.NORTH);
principal.add(rejoindre,BorderLayout.WEST);
/*------------------------panel creer------------------------*/
rejoindre.add(centrage, BorderLayout.CENTER);
rejoindre.add(vide, BorderLayout.NORTH);
rejoindre.add(vide, BorderLayout.NORTH);
principal.add(rejoindre, BorderLayout.WEST);
vide = new JPanel();
vide.setPreferredSize(new Dimension(150,150));
vide.setPreferredSize(new Dimension(500,500));
principal.add(vide,BorderLayout.EAST);
vide.setVisible(false);
}
/*------------------------panel creer------------------------*/
else {
JPanel vide = new JPanel();
vide.setPreferredSize(new Dimension(150, 150));
JPanel panelPseudo = new JPanel();
panelPseudo.setLayout(new GridLayout(2,2));
panelPseudo.setLayout(new GridLayout(2, 2));
choixPseudoHost = new JTextField();
choixPseudoHost.setText(appli.getPlayer().getName());
entreePseudoLabel = new JLabel("Entrez votre pseudo : ");
panelPseudo.add(entreePseudoLabel); panelPseudo.add(choixPseudoHost);
panelPseudo.add(new JPanel()); panelPseudo.add(new JPanel());
panelPseudo.add(entreePseudoLabel);
panelPseudo.add(choixPseudoHost);
panelPseudo.add(new JPanel());
panelPseudo.add(new JPanel());
try {
retourMenu = new JButton(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonHome1.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourMenu.setRolloverIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonHome1Hover.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourMenu.setPressedIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonHome1Pressed.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourCreation = new JButton(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonRetour1.png")))
.getScaledInstance((int) DIMENSION_RETOUR_CREATION.getWidth(),
(int) DIMENSION_RETOUR_CREATION.getHeight(), Image.SCALE_SMOOTH))));
retourCreation.setRolloverIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonRetour1Hover.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
retourCreation.setPressedIcon((new ImageIcon(
(ImageIO.read(new File("img/interface/bouton/optPartie/BoutonRetour1Pressed.png")))
.getScaledInstance((int) DIMENSION_RETOUR_MENU.getWidth(),
(int) DIMENSION_RETOUR_MENU.getHeight(), Image.SCALE_SMOOTH))));
hostPartie = new JButton(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonCreer1.png")))
.getScaledInstance((int) DIMENSION_HOST.getWidth(),
(int) DIMENSION_HOST.getHeight(), Image.SCALE_SMOOTH))));
hostPartie.setRolloverIcon(
(new ImageIcon((ImageIO.read(new File("img/interface/bouton/optPartie/BoutonCreer1Hover.png")))
.getScaledInstance((int) DIMENSION_HOST.getWidth(),
(int) DIMENSION_HOST.getHeight(), Image.SCALE_SMOOTH))));
hostPartie.setPressedIcon((new ImageIcon(
(ImageIO.read(new File("img/interface/bouton/optPartie/BoutonCreer1Pressed.png")))
.getScaledInstance((int) DIMENSION_HOST.getWidth(),
(int) DIMENSION_HOST.getHeight(), Image.SCALE_SMOOTH))));
} catch (IOException e) {
retourMenu = new JButton("retour");
retourCreation = new JButton("retour à la création de flotte");
System.out.println("erreur lors du chargement d'une image");
hostPartie = new JButton("Créer une partie");
e.printStackTrace();
}
retourMenu.setPreferredSize(DIMENSION_RETOUR_MENU);
retourCreation.setPreferredSize(DIMENSION_RETOUR_CREATION);
hostPartie.setPreferredSize(DIMENSION_HOST);
hostPartie = new JButton("Créer la partie");
boutonCarryHost = new JPanel();
boutonCarryHost.setLayout(new BoxLayout(boutonCarryHost,BoxLayout.X_AXIS));
boutonCarryHost.setLayout(new BoxLayout(boutonCarryHost, BoxLayout.X_AXIS));
boutonCarryHost.add(retourCreation);
boutonCarryHost.add(gap[3]);
boutonCarryHost.add(gap[0]);
boutonCarryHost.add(retourMenu);
boutonCarryHost.add(gap[4]);
boutonCarryHost.add(gap[1]);
boutonCarryHost.add(hostPartie);
heberger.add(panelPseudo, BorderLayout.CENTER);
heberger.add(boutonCarryHost, BorderLayout.SOUTH);
heberger.setVisible(false);
heberger.add(vide,BorderLayout.NORTH);
principal.add(heberger,BorderLayout.EAST);
heberger.add(vide, BorderLayout.NORTH);
principal.add(heberger, BorderLayout.EAST);
vide = new JPanel();
vide.setPreferredSize(new Dimension(500,500));
principal.add(vide,BorderLayout.WEST);
vide.setVisible(false);
}
/*------------------------fin des layouts------------------------*/
principal.setVisible(true);
......@@ -162,41 +267,37 @@ public class OptPartie extends JPanel {
this.setPreferredSize(new Dimension(750, 400));
}
public void afficherHeberger() {//useless du coup ?
public void afficherHeberger() {// useless du coup ?
changerTitre("creer une partie");
heberger.setVisible(true);
rejoindre.setVisible(false);
}
public void afficherRejoindre() { //pareil
public void afficherRejoindre() { // pareil
changerTitre("rejoindre une partie");
heberger.setVisible(false);
rejoindre.setVisible(true);
}
public void changerTitre(String nouveau) {
this.setName(nouveau);
}
public String getPseudoHost(){
public String getPseudoHost() {
return choixPseudoHost.getText();
}
public String getPseudoJoin(){
public String getPseudoJoin() {
return choixPseudoJoin.getText();
}
public String getChercher(){
public String getChercher() {
return recherche.getText();
}
public void actualiserPage(){
if(join || host)
{
this.rejoindre.setVisible(join);
this.heberger.setVisible(!join);
//foreach partie dans la liste partie : créer un nouveau ensemble de composants
// contenant : player.getName et game.getID + type (belge, fr) et bouton rejoindre
}
public void actualiserPage() {
this.rejoindre.setVisible(!host);
this.heberger.setVisible(host);
}
public void actualiserListe() {
......@@ -211,33 +312,37 @@ public class OptPartie extends JPanel {
}
for (Game game : newListe) {
if (game.toString().toLowerCase().contains(recherche.getText().toLowerCase())){
if (game.toString().toLowerCase().contains(recherche.getText().toLowerCase())) {
listModel.addElement(game);
}
}
}
public Game getPartie(){
public Game getPartie() {
return parties.getSelectedValue();
}
public void fixeListenerRecherche(KeyListener l){
public void fixeListenerRecherche(KeyListener l) {
recherche.addKeyListener(l);
}
public void fixeListenerActualiserListe(ActionListener l){
public void fixeListenerActualiserListe(ActionListener l) {
actualiser.addActionListener(l);
}
public void fixeListenerRetourMenu(ActionListener l){
public void fixeListenerRetourMenu(ActionListener l) {
retourMenu.addActionListener(l);
}
public void fixeListenerRetourCreationFlotte(ActionListener l){
public void fixeListenerRetourCreationFlotte(ActionListener l) {
retourCreation.addActionListener(l);
}
public void fixeListenerJoin(ActionListener l){
public void fixeListenerJoin(ActionListener l) {
joinPartie.addActionListener(l);
}
public void fixeListenerHost(ActionListener l){
public void fixeListenerHost(ActionListener l) {
hostPartie.addActionListener(l);
}
......
......@@ -4,6 +4,7 @@ import java.awt.Color;
import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import com.mashape.unirest.http.exceptions.UnirestException;
......@@ -119,7 +120,7 @@ public class appli {
}
public static void afficherOptPartie(boolean heberger) {
OptPartie optionsPartie = new OptPartie("Que voulez vous faire ?");
OptPartie optionsPartie = new OptPartie("Que voulez vous faire ?",heberger);
if (heberger){
optionsPartie.afficherHeberger();
optionsPartie.fixeListenerRetourMenu(new RetourAuMenuControleur());
......@@ -216,7 +217,7 @@ public class appli {
if (component instanceof JPanel){
setBgColorComponents((JPanel) component, c);
}
component.setForeground(component instanceof JTextField ? c : Color.WHITE);
component.setForeground(component instanceof JTextField ? c : component instanceof JProgressBar ? Color.RED : Color.WHITE);
component.setBackground(component instanceof JTextField ? Color.WHITE : c);
}
jPanel.setOpaque(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment