Advertisement
Guest User

Untitled

a guest
May 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. import javax.imageio.ImageIO;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.image.BufferedImage;
  7. import java.io.File;
  8. import java.io.IOException;
  9.  
  10. public class Acceuil extends JFrame implements ActionListener{
  11.  
  12. Model model;
  13. JLabel titre;
  14. JButton newGame;
  15. JButton multi;
  16. JButton bestScores;
  17.  
  18. JPanel panAcceuil;
  19.  
  20. public Acceuil(Model model) throws IOException {
  21. this.model=model;
  22. initAttribut();
  23. creerWidget();
  24.  
  25. setSize(500, 500);
  26. setVisible(true);
  27. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. setResizable(false);
  29. setTitle("Snake");
  30. }
  31.  
  32. public void initAttribut() throws IOException {
  33.  
  34. panAcceuil = setBackgroundImage(this, new File("background/fond.jpg"));
  35. titre = new JLabel(new ImageIcon("background/snake.jpg"));
  36. newGame = new JButton("Nouvelle Partie");
  37. multi = new JButton("Multijoueur");
  38. bestScores = new JButton("Meilleurs Scores");
  39. }
  40.  
  41. public void creerWidget(){
  42. JPanel panMenu = new JPanel(new GridBagLayout());
  43. panMenu.setOpaque(false);
  44. GridBagConstraints gbc = new GridBagConstraints();
  45. gbc.fill = GridBagConstraints.BOTH;
  46. gbc.insets = new Insets(100, 0, 0, 0);
  47. gbc.gridx = 0;
  48.  
  49. gbc.gridy = 0;
  50. panMenu.add(titre,gbc);
  51.  
  52. gbc.insets = new Insets(25, 0, 0, 0);
  53. gbc.gridy = 1;
  54. panMenu.add(newGame,gbc);
  55.  
  56. gbc.gridy = 2;
  57. panMenu.add(multi, gbc);
  58.  
  59. gbc.gridy = 3;
  60. panMenu.add(bestScores, gbc);
  61.  
  62. panAcceuil.add(panMenu/*, BorderLayout.CENTER*/);
  63. setContentPane(panAcceuil);
  64. }
  65.  
  66. public void display() {
  67. setVisible(true);
  68. }
  69.  
  70. @Override
  71. public void actionPerformed(ActionEvent e) {
  72.  
  73. }
  74.  
  75. public static JPanel setBackgroundImage(Acceuil acceuil, final File img) throws IOException
  76. {
  77. JPanel panel = new JPanel()
  78. {
  79. private static final long serialVersionUID = 1;
  80.  
  81. private BufferedImage buf = ImageIO.read(img);
  82.  
  83. @Override
  84. protected void paintComponent(Graphics g)
  85. {
  86. super.paintComponent(g);
  87. g.drawImage(buf, 0,0, null);
  88. }
  89. };
  90.  
  91. acceuil.setContentPane(panel);
  92.  
  93. return panel;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement