package projet; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Graphics; public class Projet { static JButton bouton1,bouton2,bouton3,bouton4,bouton5,bouton6,bouton7,bouton8,bouton9,bouton10,bouton11,bouton12; static JFrame f; static JPanel pan, pan1; static ecouteurbouton eb; static int c; static class Dessin extends JPanel { @Override public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.BLACK); g.fillOval(10,10,10,10); //g.drawOval(10, 10, 20, 20); pan1.repaint(); //pan1.setBackground(Color.CYAN); } } static public class ecouteurbouton implements ActionListener { @Override public void actionPerformed (ActionEvent e) { Object bouton= e.getSource(); if (bouton==bouton1){ c = c+1; } if (bouton==bouton2){ c = c+1; } if (bouton==bouton3){ c = c+1; } if (bouton==bouton4){ c = c+1; } if (bouton==bouton5){ c = c+1; } if (bouton==bouton6){ c = c+1; } if (bouton==bouton7){ c = c+1; } if (bouton==bouton8){ c = c+1; } if (bouton==bouton9){ c = c+1; } if (bouton==bouton10){ c = c+1; } if (bouton==bouton11){ c = c+1; } } } public static void main(String[] args) { f = new JFrame("Partition"); pan = new JPanel(); pan1 = new JPanel (); eb = new ecouteurbouton(); c = 0; bouton1 = new JButton(""); bouton2 = new JButton(""); bouton3 = new JButton(""); bouton4 = new JButton(""); bouton5 = new JButton(""); bouton6 = new JButton(""); bouton7 = new JButton(""); bouton8 = new JButton(""); bouton9 = new JButton(""); bouton10 = new JButton(""); bouton11 = new JButton(""); bouton12 = new JButton(""); f.setLayout(null); f.setSize(1000,350); pan.setBackground(Color.CYAN); pan.setLayout(null); pan1.setLayout(new BorderLayout()); pan1.setOpaque(false); pan1.add(new Dessin(), BorderLayout.CENTER); pan1.setSize(1000,350); //Couleur des boutons bouton1.setBackground(Color.WHITE); bouton2.setBackground(Color.BLACK); bouton3.setBackground(Color.WHITE); bouton4.setBackground(Color.BLACK); bouton5.setBackground(Color.WHITE); bouton6.setBackground(Color.BLACK); bouton7.setBackground(Color.WHITE); bouton8.setBackground(Color.BLACK); bouton9.setBackground(Color.WHITE); bouton10.setBackground(Color.BLACK); bouton11.setBackground(Color.WHITE); bouton12.setBackground(Color.CYAN); //Taille des boutons bouton1.setBounds(50,50,900,25); bouton2.setBounds(50,75,900,10); bouton3.setBounds(50,85,900,25); bouton4.setBounds(50,110,900,10); bouton5.setBounds(50,120,900,25); bouton6.setBounds(50,145,900,10); bouton7.setBounds(50,155,900,25); bouton8.setBounds(50,180,900,10); bouton9.setBounds(50,190,900,25); bouton10.setBounds(50,215,900,10); bouton11.setBounds(50,225,900,25); bouton12.setBounds(50,250,900,20); //Ajout des boutons pan.add(bouton1); pan.add(bouton2); pan.add(bouton3); pan.add(bouton4); pan.add(bouton5); pan.add(bouton6); pan.add(bouton7); pan.add(bouton8); pan.add(bouton9); pan.add(bouton10); pan.add(bouton11); pan.add(bouton12); //Mise sur écoute des boutons bouton1.addActionListener(eb); bouton2.addActionListener(eb); bouton3.addActionListener(eb); bouton4.addActionListener(eb); bouton5.addActionListener(eb); bouton6.addActionListener(eb); bouton7.addActionListener(eb); bouton8.addActionListener(eb); bouton9.addActionListener(eb); bouton10.addActionListener(eb); bouton11.addActionListener(eb); bouton12.addActionListener(eb); f.setContentPane(pan); f.add(pan1); f.setVisible(true); f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); } }