Advertisement
Guest User

Untitled

a guest
May 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.GridLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.WindowAdapter;
  7. import java.awt.event.WindowEvent;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JLabel;
  12. import javax.swing.JPanel;
  13. import javax.swing.SwingUtilities;
  14. import javax.swing.UIManager;
  15. import javax.swing.UnsupportedLookAndFeelException;
  16. import javax.swing.plaf.metal.*;
  17.  
  18. @SuppressWarnings("serial")
  19. public class Grid extends JFrame
  20. {
  21. private final static int COTE=8;
  22. private static JPanel Panel;
  23.  
  24. public Grid () throws UnsupportedLookAndFeelException
  25. {
  26. super("Echecs");
  27. UIManager.setLookAndFeel(new MetalLookAndFeel());
  28. addWindowListener(new WindowAdapter()
  29. {
  30. public void windowClosing(WindowEvent e)
  31. { System.exit(0); }
  32. });
  33. }
  34.  
  35. public static void main(String[] args) throws UnsupportedLookAndFeelException
  36. {
  37. Grid Cadre=new Grid();
  38. JButton[] Bouton= new JButton[COTE*COTE];
  39. String Coord;
  40. Panel = new JPanel();
  41. Panel.setLayout(new GridLayout(COTE,COTE));
  42. Cadre.add(Panel);
  43.  
  44. for (int i=0 ;i < COTE*COTE;++i)
  45. {
  46. Bouton[i]= new JButton ();
  47. Bouton[i].setPreferredSize(new Dimension (40,40));
  48.  
  49. if ( i%2 == (i/8)%2 )
  50. Bouton[i].setBackground(Color.WHITE);
  51. else
  52. Bouton[i].setBackground(Color.GRAY);
  53. Coord = "A1";
  54. //Bouton[i].setActionCommand(Coord);
  55.  
  56. Bouton[i].addActionListener(new Ecouteur());
  57.  
  58. Panel.add(Bouton[i]);
  59. // Case centré
  60. //JPanel PanelInter = new JPanel();
  61. //PanelInter.add(Bouton[i]);
  62. //Panel.add(PanelInter);
  63. }
  64.  
  65. Cadre.pack();
  66. Cadre.setVisible(true);
  67.  
  68. }
  69.  
  70. class Ecouteur implements ActionListener
  71. {
  72.  
  73. Ecouteur()
  74. {
  75. }
  76.  
  77. public void actionPerformed(ActionEvent evt)
  78. {
  79. evt.getActionCommand();
  80. }
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement