Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.SwingUtilities;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- import javax.swing.plaf.metal.*;
- @SuppressWarnings("serial")
- public class Grid extends JFrame
- {
- private final static int COTE=8;
- private static JPanel Panel;
- public Grid () throws UnsupportedLookAndFeelException
- {
- super("Echecs");
- UIManager.setLookAndFeel(new MetalLookAndFeel());
- addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- { System.exit(0); }
- });
- }
- public static void main(String[] args) throws UnsupportedLookAndFeelException
- {
- Grid Cadre=new Grid();
- JButton[] Bouton= new JButton[COTE*COTE];
- String Coord;
- Panel = new JPanel();
- Panel.setLayout(new GridLayout(COTE,COTE));
- Cadre.add(Panel);
- for (int i=0 ;i < COTE*COTE;++i)
- {
- Bouton[i]= new JButton ();
- Bouton[i].setPreferredSize(new Dimension (40,40));
- if ( i%2 == (i/8)%2 )
- Bouton[i].setBackground(Color.WHITE);
- else
- Bouton[i].setBackground(Color.GRAY);
- Coord = "A1";
- //Bouton[i].setActionCommand(Coord);
- Bouton[i].addActionListener(new Ecouteur());
- Panel.add(Bouton[i]);
- // Case centré
- //JPanel PanelInter = new JPanel();
- //PanelInter.add(Bouton[i]);
- //Panel.add(PanelInter);
- }
- Cadre.pack();
- Cadre.setVisible(true);
- }
- class Ecouteur implements ActionListener
- {
- Ecouteur()
- {
- }
- public void actionPerformed(ActionEvent evt)
- {
- evt.getActionCommand();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement