Soyez le premier à donner votre avis sur cette source.
Vue 13 148 fois - Téléchargée 1 632 fois
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestBuffer extends JFrame implements ActionListener { public Bufer buffer; public Producteur producteur; public Consommateur consommateur; public Container container; public ImageIcon[] image; public JButton compteur; public JPanel totale; public JPanel producteurP; public JPanel consommateurP; public JPanel controler; public JPanel p_controler; public JPanel c_controler; public JLabel titre; public ImageIcon pro_img; public ImageIcon con_img; public JButton pro; public JButton con; public ImageIcon on_img; public ImageIcon off_img; public JButton pro_on; public JButton con_on; public JButton pro_off; public JButton con_off; public ImageIcon xon_img; public ImageIcon xoff_img; public JButton xon; public JButton xoff; public ImageIcon controle_img; public JButton controle; public static TestBuffer t; public ImageIcon logo; public TestBuffer() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(this); } catch (Exception e) { System.out.println("FrmUsers.FrmUsers : impossible d'appliquer le thème du système"); } logo = new ImageIcon("logo.png"); this.setIconImage(logo.getImage()); this.setTitle("Producteur/Consommateur"); controle_img=new ImageIcon("controle.png"); controle=new JButton(); controle.setIcon(controle_img); pro_img=new ImageIcon("producteur.png"); con_img=new ImageIcon("consommateur.png"); pro=new JButton(); pro.setIcon(pro_img); con=new JButton(); con.setIcon(con_img); xon_img=new ImageIcon("xon.png"); xoff_img=new ImageIcon("xoff.png"); xon=new JButton(); xon.setIcon(xon_img); xoff=new JButton(); xoff.setIcon(xoff_img); on_img=new ImageIcon("on.png"); off_img=new ImageIcon("off.png"); pro_on=new JButton(); pro_on.setIcon(on_img); con_on=new JButton(); con_on.setIcon(on_img); pro_off=new JButton(); pro_off.setIcon(off_img); con_off=new JButton(); con_off.setIcon(off_img); totale = new JPanel(); totale.setLayout(new BoxLayout(totale, BoxLayout.Y_AXIS)); controler = new JPanel(); controler.setLayout(new BoxLayout(controler,BoxLayout.X_AXIS)); producteurP = new JPanel(); producteurP.setLayout(new BoxLayout(producteurP, BoxLayout.X_AXIS)); p_controler = new JPanel(); p_controler.setLayout(new BoxLayout(p_controler, BoxLayout.Y_AXIS)); p_controler.add(pro_on); p_controler.add(pro_off); producteurP.add(pro); producteurP.add(p_controler); controler.add(producteurP); controler.add(xoff); controler.add(xon); consommateurP = new JPanel(); consommateurP.setLayout(new BoxLayout(consommateurP, BoxLayout.X_AXIS)); c_controler = new JPanel(); c_controler.setLayout(new BoxLayout(c_controler, BoxLayout.Y_AXIS)); c_controler.add(con_on); c_controler.add(con_off); consommateurP.add(c_controler); consommateurP.add(con); controler.add(consommateurP); totale.add(controler); compteur=new JButton(); image = new ImageIcon[10]; for(int i=0;i<10;i++) { image[i] = new ImageIcon(i+".png"); System.out.println(image[i]); } compteur.setIcon(image[0]); container=this.getContentPane(); buffer = new Bufer(10,compteur,image); producteur = new Producteur (buffer); consommateur = new Consommateur (buffer); container.add(compteur,BorderLayout.NORTH); container.add(controle,BorderLayout.CENTER); container.add(totale,BorderLayout.SOUTH); this.setVisible(true); this.pack(); pro_on.addActionListener(this); pro_off.addActionListener(this); con_on.addActionListener(this); con_off.addActionListener(this); xon.addActionListener(this); xoff.addActionListener(this); } public static void main(String args[]) { t=new TestBuffer(); t.producteur.start(); t.consommateur.start(); } public void actionPerformed(ActionEvent action) { if(action.getSource().equals(pro_on)) { t.producteur=new Producteur (buffer); t.producteur.start(); } if(action.getSource().equals(pro_off)) { t.producteur.stop(); } if(action.getSource().equals(con_on)) { t.consommateur=new Consommateur (buffer); t.consommateur.start(); } if(action.getSource().equals(con_off)) { t.consommateur.stop(); } if(action.getSource().equals(xon)) { t.producteur=new Producteur (buffer); t.consommateur=new Consommateur (buffer); t.producteur.start(); t.consommateur.start(); } if(action.getSource().equals(xoff)) { t.producteur.stop(); t.consommateur.stop(); } } }
la preuve : lance ton application puis ferme la et essaie de déplacer le dossier de l'application et tu aura un message indiquant que le dossier est utilisé..
je vois pas ou la perte mémoire
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.