Téléverser les fichiers vers "src/main/java/view"
This commit is contained in:
parent
96d264a4df
commit
60fc941fef
src/main/java/view
24
src/main/java/view/BtnPerso.java
Normal file
24
src/main/java/view/BtnPerso.java
Normal file
@ -0,0 +1,24 @@
|
||||
package view;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
public class BtnPerso extends JButton {
|
||||
|
||||
public BtnPerso(String text){
|
||||
super(text);
|
||||
setFont(new Font("Helvetica", Font.BOLD,25));
|
||||
setContentAreaFilled(false);
|
||||
setForeground(Color.BLACK);
|
||||
setBorderPainted(false);
|
||||
setOpaque(true);
|
||||
setFocusPainted(false);
|
||||
setBackground(new Color(243, 171, 115, 150));
|
||||
|
||||
Dimension d = new Dimension(200,50);
|
||||
setPreferredSize(d);
|
||||
}
|
||||
|
||||
|
||||
}
|
28
src/main/java/view/ButtonHoverListener.java
Normal file
28
src/main/java/view/ButtonHoverListener.java
Normal file
@ -0,0 +1,28 @@
|
||||
package view;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.Color;
|
||||
|
||||
public class ButtonHoverListener extends MouseAdapter {
|
||||
|
||||
private Color hoverColor = new Color(200, 150, 100);
|
||||
private Color normalColor = new Color(243, 171, 115, 150);
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (e.getSource() instanceof JButton) {
|
||||
JButton button = (JButton) e.getSource();
|
||||
button.setBackground(hoverColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (e.getSource() instanceof JButton) {
|
||||
JButton button = (JButton) e.getSource();
|
||||
button.setBackground(normalColor);
|
||||
}
|
||||
}
|
||||
}
|
108
src/main/java/view/MenuView.java
Normal file
108
src/main/java/view/MenuView.java
Normal file
@ -0,0 +1,108 @@
|
||||
package view;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
public class MenuView extends JComponent {
|
||||
private BtnPerso resumeButton;
|
||||
private BtnPerso newGameButton;
|
||||
private JButton quitButton;
|
||||
|
||||
private Image backgroundImage;
|
||||
private ImageIcon logo;
|
||||
private ImageIcon quit;
|
||||
private JPanel panelCoté;
|
||||
private JLabel labelImg;
|
||||
|
||||
|
||||
|
||||
|
||||
public MenuView(){
|
||||
|
||||
panelCoté = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
panelCoté.setBackground(new Color(243,171,115,150));
|
||||
panelCoté.setPreferredSize(new Dimension(300,0));
|
||||
|
||||
backgroundImage = new ImageIcon("\\\\wsl.localhost\\Ubuntu-24.04\\home\\topb\\DEV\\SAE31_2024\\src\\main\\java\\view\\img\\bg.png").getImage();
|
||||
logo = new ImageIcon("\\\\wsl.localhost\\Ubuntu-24.04\\home\\topb\\DEV\\SAE31_2024\\src\\main\\java\\view\\img\\D.png");
|
||||
quit = new ImageIcon("\\\\wsl.localhost\\Ubuntu-24.04\\home\\topb\\DEV\\SAE31_2024\\src\\main\\java\\view\\img\\quit.png");
|
||||
Image quit1 = quit.getImage();
|
||||
Image lg = logo.getImage();
|
||||
Image resizedlg = lg.getScaledInstance(300, 300, Image.SCALE_SMOOTH);
|
||||
ImageIcon logoIcon = new ImageIcon(resizedlg);
|
||||
|
||||
|
||||
|
||||
labelImg = new JLabel(logoIcon);
|
||||
|
||||
|
||||
|
||||
resumeButton = new BtnPerso("RESUME");
|
||||
newGameButton = new BtnPerso("NEW GAME");
|
||||
|
||||
int buttonWidth = 65;
|
||||
int buttonHeight = 40;
|
||||
Image resizedImage = quit1.getScaledInstance(buttonWidth, buttonHeight, Image.SCALE_SMOOTH);
|
||||
ImageIcon resizedIcon = new ImageIcon(resizedImage);
|
||||
|
||||
quitButton = new JButton(resizedIcon);
|
||||
quitButton.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
|
||||
quitButton.setPreferredSize(new Dimension(50,50));
|
||||
quitButton.setBackground(new Color(243, 171, 115, 150));
|
||||
quitButton.setBorderPainted(false);
|
||||
quitButton.setOpaque(true);
|
||||
quitButton.setFocusPainted(false);
|
||||
|
||||
ButtonHoverListener hoverListener = new ButtonHoverListener();
|
||||
resumeButton.addMouseListener(hoverListener);
|
||||
newGameButton.addMouseListener(hoverListener);
|
||||
quitButton.addMouseListener(hoverListener);
|
||||
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.insets = new Insets(10, 10, 10, 10);
|
||||
gbc.weightx = 1.0;
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
|
||||
panelCoté.add(labelImg,gbc);
|
||||
|
||||
|
||||
gbc.gridy = 1;
|
||||
panelCoté.add(resumeButton,gbc);
|
||||
|
||||
|
||||
gbc.gridy = 2;
|
||||
panelCoté.add(newGameButton, gbc);
|
||||
|
||||
gbc.gridy = 3;
|
||||
panelCoté.add(quitButton, gbc);
|
||||
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(panelCoté,BorderLayout.WEST);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
|
||||
}
|
||||
public BtnPerso getResumeButton() {
|
||||
return resumeButton;
|
||||
}
|
||||
|
||||
public BtnPerso getNewGameButton() {
|
||||
return newGameButton;
|
||||
}
|
||||
|
||||
public JButton getQuiButton(){
|
||||
return quitButton;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user