Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- public class Acceuil extends JFrame implements ActionListener{
- Model model;
- JLabel titre;
- JButton newGame;
- JButton multi;
- JButton bestScores;
- JPanel panAcceuil;
- public Acceuil(Model model) throws IOException {
- this.model=model;
- initAttribut();
- creerWidget();
- setSize(500, 500);
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setResizable(false);
- setTitle("Snake");
- }
- public void initAttribut() throws IOException {
- panAcceuil = setBackgroundImage(this, new File("background/fond.jpg"));
- titre = new JLabel(new ImageIcon("background/snake.jpg"));
- newGame = new JButton("Nouvelle Partie");
- multi = new JButton("Multijoueur");
- bestScores = new JButton("Meilleurs Scores");
- }
- public void creerWidget(){
- JPanel panMenu = new JPanel(new GridBagLayout());
- panMenu.setOpaque(false);
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.fill = GridBagConstraints.BOTH;
- gbc.insets = new Insets(100, 0, 0, 0);
- gbc.gridx = 0;
- gbc.gridy = 0;
- panMenu.add(titre,gbc);
- gbc.insets = new Insets(25, 0, 0, 0);
- gbc.gridy = 1;
- panMenu.add(newGame,gbc);
- gbc.gridy = 2;
- panMenu.add(multi, gbc);
- gbc.gridy = 3;
- panMenu.add(bestScores, gbc);
- panAcceuil.add(panMenu/*, BorderLayout.CENTER*/);
- setContentPane(panAcceuil);
- }
- public void display() {
- setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- public static JPanel setBackgroundImage(Acceuil acceuil, final File img) throws IOException
- {
- JPanel panel = new JPanel()
- {
- private static final long serialVersionUID = 1;
- private BufferedImage buf = ImageIO.read(img);
- @Override
- protected void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- g.drawImage(buf, 0,0, null);
- }
- };
- acceuil.setContentPane(panel);
- return panel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement