ajout des boutons non ergo au menu
This commit is contained in:
36
TestV1/src/Controller/MenuController.java
Normal file
36
TestV1/src/Controller/MenuController.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package Controller; // Spécifie que cette classe fait partie du package Controller
|
||||
|
||||
import Model.MenuModel; // Importer la classe MenuModel
|
||||
import View.MenuView;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MenuController {
|
||||
private MenuModel model;
|
||||
private MenuView view;
|
||||
|
||||
public MenuController(MenuModel model, MenuView view) {
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Initialiser le modèle avec le chemin de l'image
|
||||
MenuModel model = new MenuModel("../res/fond-ecran.jpg");
|
||||
|
||||
// Créer la vue en lui passant l'image de fond
|
||||
MenuView view = new MenuView(model);
|
||||
|
||||
// Démarrer le contrôleur
|
||||
new MenuController(model, view).run();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
62
TestV1/src/Makefile
Normal file
62
TestV1/src/Makefile
Normal file
@@ -0,0 +1,62 @@
|
||||
### VARIABLES ###
|
||||
|
||||
JC = javac
|
||||
JCFLAGS = -encoding UTF-8 -implicit:none
|
||||
|
||||
JVM = java
|
||||
JVMFLAGS =
|
||||
|
||||
# Chemins des dossiers
|
||||
SRC_CONTROLLER = Controller
|
||||
SRC_MODEL = Model
|
||||
SRC_VIEW = View
|
||||
|
||||
# Cibles pour chaque fichier .class avec leurs chemins respectifs
|
||||
CONTROLLER_CLASS = $(SRC_CONTROLLER)/MenuController.class
|
||||
MODEL_CLASS = $(SRC_MODEL)/MenuModel.class
|
||||
VIEW_CLASS = $(SRC_VIEW)/MenuView.class
|
||||
PANEL_CLASS = $(SRC_VIEW)/PanneauImage.class
|
||||
TITRE_CLASS = $(SRC_VIEW)/TitreView.class
|
||||
BOUTON_CLASS = $(SRC_VIEW)/BoutonView.class
|
||||
### REGLES ESSENTIELLES ###
|
||||
|
||||
# Règle pour compiler MenuController
|
||||
$(CONTROLLER_CLASS): $(SRC_CONTROLLER)/MenuController.java $(MODEL_CLASS) $(VIEW_CLASS) $(PANEL_CLASS) $(TITRE_CLASS) $(BOUTON_CLASS)
|
||||
${JC} ${JCFLAGS} -d . $(SRC_CONTROLLER)/MenuController.java
|
||||
|
||||
# Règle pour compiler MenuModel
|
||||
$(MODEL_CLASS): $(SRC_MODEL)/MenuModel.java
|
||||
${JC} ${JCFLAGS} -d . $(SRC_MODEL)/MenuModel.java
|
||||
|
||||
# Règle pour compiler MenuView
|
||||
$(VIEW_CLASS): $(SRC_VIEW)/MenuView.java $(PANEL_CLASS) $(TITRE_CLASS) $(BOUTON_CLASS)
|
||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/MenuView.java
|
||||
|
||||
# Règle pour compiler PanneauImage
|
||||
$(PANEL_CLASS): $(SRC_VIEW)/PanneauImage.java
|
||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/PanneauImage.java
|
||||
|
||||
# Règle pour compiler TitreView
|
||||
$(TITRE_CLASS): $(SRC_VIEW)/TitreView.java # Règle pour compiler TitreView
|
||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/TitreView.java
|
||||
|
||||
# Règle pour compiler BoutonView
|
||||
$(TITRE_CLASS): $(SRC_VIEW)/BoutonView.java # Règle pour compiler TitreView
|
||||
${JC} ${JCFLAGS} -d . $(SRC_VIEW)/BoutonView.java
|
||||
|
||||
### REGLES OPTIONNELLES ###
|
||||
|
||||
# Règle pour exécuter l'application
|
||||
run: $(CONTROLLER_CLASS)
|
||||
${JVM} ${JVMFLAGS} Controller.MenuController
|
||||
|
||||
# Règle pour nettoyer les fichiers .class
|
||||
clean:
|
||||
-rm -f $(SRC_CONTROLLER)/*.class $(SRC_MODEL)/*.class $(SRC_VIEW)/*.class
|
||||
|
||||
# Règle pour tout nettoyer et recompiler
|
||||
mrproper: clean $(CONTROLLER_CLASS)
|
||||
|
||||
### BUTS FACTICES ###
|
||||
|
||||
.PHONY: run clean mrproper
|
23
TestV1/src/Model/MenuModel.java
Normal file
23
TestV1/src/Model/MenuModel.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package Model;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class MenuModel {
|
||||
private Image imageDeFond;
|
||||
|
||||
public MenuModel(String imagePath) {
|
||||
// Charger l'image de fond
|
||||
try {
|
||||
imageDeFond = ImageIO.read(new File("../res/fond-ecran.jpg!d"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Image getImageDeFond() {
|
||||
return imageDeFond;
|
||||
}
|
||||
}
|
19
TestV1/src/View/BoutonView.java
Normal file
19
TestV1/src/View/BoutonView.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package View;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class BoutonView extends JButton {
|
||||
public BoutonView(String texte) {
|
||||
super(texte);
|
||||
|
||||
setFont(new Font("Arial", Font.BOLD, 40));
|
||||
setForeground(Color.WHITE); // Couleur du texte blanc
|
||||
setFocusPainted(false); // Enlever le focus sur le bouton
|
||||
setBorderPainted(false); // Enlever la bordure par défaut
|
||||
setContentAreaFilled(false); // Fond transparent
|
||||
setOpaque(false); // Ne dessine pas le fond par défaut
|
||||
|
||||
}
|
||||
}
|
51
TestV1/src/View/MenuView.java
Normal file
51
TestV1/src/View/MenuView.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package View;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import Model.MenuModel;
|
||||
|
||||
public class MenuView extends JFrame {
|
||||
private PanneauImage panneauImage;
|
||||
private TitreView titreView;
|
||||
private BoutonView boutonJouer;
|
||||
private BoutonView boutonCommentJouer;
|
||||
private BoutonView boutonQuitter;
|
||||
|
||||
public MenuView(MenuModel model) {
|
||||
|
||||
setTitle("Dorfromantik");
|
||||
setSize(800, 600);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
panneauImage = new PanneauImage(model.getImageDeFond());
|
||||
setContentPane(panneauImage);
|
||||
titreView = new TitreView();
|
||||
|
||||
JPanel panelTitre = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
panelTitre.setOpaque(false);
|
||||
panelTitre.add(titreView.getTitre());
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(panelTitre, BorderLayout.NORTH);
|
||||
|
||||
JPanel panelBouton = new JPanel();
|
||||
panelBouton.setOpaque(false); // Panneau transparent pour ne pas couvrir l'image de fond
|
||||
panelBouton.setLayout(new BoxLayout(panelBouton, BoxLayout.Y_AXIS)); // Disposition verticale
|
||||
|
||||
// Initialisation des boutons
|
||||
boutonJouer = new BoutonView("Jouer");
|
||||
boutonCommentJouer = new BoutonView("Comment Jouer ?");
|
||||
boutonQuitter = new BoutonView("Quitter");
|
||||
|
||||
panelBouton.add(boutonJouer);
|
||||
panelBouton.add(Box.createVerticalStrut(10)); // Espace entre les boutons
|
||||
panelBouton.add(boutonCommentJouer);
|
||||
panelBouton.add(Box.createVerticalStrut(10)); // Espace entre les boutons
|
||||
panelBouton.add(boutonQuitter);
|
||||
|
||||
add(panelBouton, BorderLayout.SOUTH);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
20
TestV1/src/View/PanneauImage.java
Normal file
20
TestV1/src/View/PanneauImage.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package View;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class PanneauImage extends JPanel {
|
||||
private Image imageDeFond;
|
||||
|
||||
public PanneauImage(Image image) {
|
||||
this.imageDeFond = image;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (imageDeFond != null) {
|
||||
g.drawImage(imageDeFond, 0, 0, getWidth(), getHeight(), this);
|
||||
}
|
||||
}
|
||||
}
|
68
TestV1/src/View/TitreView.java
Normal file
68
TestV1/src/View/TitreView.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package View;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class TitreView {
|
||||
private ContourLabel titre;
|
||||
|
||||
public TitreView() {
|
||||
// Créer une instance de ContourLabel avec le texte souhaité
|
||||
titre = new ContourLabel("Dorfromantik");
|
||||
|
||||
// Définir la police et les couleurs
|
||||
titre.setFont(new Font("Algerian", Font.BOLD, 70));
|
||||
titre.setForeground(Color.WHITE); // Couleur du texte principal
|
||||
titre.setContourColor(Color.BLACK); // Couleur du contour
|
||||
titre.setContourThickness(4); // Épaisseur du contour
|
||||
}
|
||||
|
||||
public JLabel getTitre() {
|
||||
return titre;
|
||||
}
|
||||
|
||||
// Classe interne pour gérer le contour autour du texte
|
||||
private static class ContourLabel extends JLabel {
|
||||
private Color contourColor = Color.BLACK;
|
||||
private int contourThickness = 2;
|
||||
|
||||
public ContourLabel(String text) {
|
||||
super(text);
|
||||
}
|
||||
|
||||
public void setContourColor(Color contourColor) {
|
||||
this.contourColor = contourColor;
|
||||
}
|
||||
|
||||
public void setContourThickness(int contourThickness) {
|
||||
this.contourThickness = contourThickness;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
|
||||
// Activer l'anti-aliasing
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// Dessiner le contour
|
||||
g2d.setFont(getFont());
|
||||
g2d.setColor(contourColor);
|
||||
g2d.setStroke(new BasicStroke(contourThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||
FontMetrics fm = g2d.getFontMetrics();
|
||||
int x = 0;
|
||||
int y = fm.getAscent();
|
||||
g2d.draw(getTextShape(g2d, getText(), x, y));
|
||||
|
||||
// Dessiner le texte principal
|
||||
g2d.setColor(getForeground());
|
||||
g2d.fill(getTextShape(g2d, getText(), x, y));
|
||||
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
private Shape getTextShape(Graphics2D g2d, String text, int x, int y) {
|
||||
return getFont().createGlyphVector(g2d.getFontRenderContext(), text).getOutline(x, y);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user