j'ai une applet ki affiche des image une fois qu'on clique sur un jmenuitem
le probleme c'est que j'ai deux panel ki reçoi des images la premiere fois k'on clique ssur le jmenuitem normalement il doit afficher dans chaque panel une image avec repaint(); mais il affiche dans les deux panel la meme imahge alors k'on a spécifié des images déffirentes j constater k'il fait le repaint() pour tous les composants et moi j veu pour chaque composants apart..voila le code..si vous pouviez me dire comment résoudre ça...merci bien
import java.awt.Image;
import javax.print.DocFlavor.URL;
import javax.swing.JApplet;
import java.awt.BorderLayout;
import java.applet.*;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.DocFlavor.URL;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Tp extends JApplet implements ActionListener,Runnable{
private javax.swing.JPanel jPanel;
private javax.swing.JPanel Compte;
private javax.swing.JTextArea CompteRendu;
private javax.swing.JPanel PHmet;
private javax.swing.JMenu action;
private javax.swing.JMenuItem affichePH;
private javax.swing.JMenuItem ajoutFeno;
private javax.swing.JMenuItem ajoutNACL;
private javax.swing.JMenuItem ajoutNAOH;
private javax.swing.JMenuItem ajoutNAOHNACL;
private javax.swing.JMenuItem augmente;
private javax.swing.JMenuItem buretteItem;
private javax.swing.JMenuItem comren;
private javax.swing.JMenuItem deminue;
private javax.swing.JButton envoyer;
private javax.swing.JMenuItem ferme;
private javax.swing.JMenuItem flaconItem;
private javax.swing.JDialog jDialog1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JOptionPane jOptionPane2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JMenu materielItem;
private javax.swing.JMenuItem nouveau;
private javax.swing.JMenuItem ouvre;
private javax.swing.JMenuItem quit;
private javax.swing.JMenuItem reouvre;
private javax.swing.JMenu vanett;
private Flacon flacon;
private Burette burette;
private Flacon flac;
private Burette buret;
private PHLbl ph;
// End of variables declaration//GEN-END:variables
public float PH= (float) 0.70;
String txt,txt1,txt2; Image icon,iconn;
//FrameThread th=null;
private boolean moving = false;
private boolean flaconplein = false;
private boolean buretteplein= false;
private boolean ouvrir = false;
private boolean fermer = false;
private boolean augmenter = false;
private boolean déminuer = false;
private boolean thr = false;
private boolean marche = false;
private boolean nouvel = false;
/*Abscisse du coin supérieur-gauche */
int FlaconERLyPosition;
int FlaconLblxPosition;
int FlaconERLxPosition;
int FlaconLblyPosition;
/*Abscisse du point où on fait glisser le carré */
private int xDragg;
public String url;
/*Ordonnée du point où on fait glisser le carré */
private int yDragg;
public boolean draged=false;
java.net.URL base,bases;
Graphics g;
Thread thread=null;
int i=4900, j=3600;double vNaoh;
public void init() {
this.setSize(1050, 750);
this.setBackground(Color.white);
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
nouveau = new javax.swing.JMenuItem();
comren = new javax.swing.JMenuItem();
quit = new javax.swing.JMenuItem();
materielItem = new javax.swing.JMenu();
buretteItem = new javax.swing.JMenuItem();
flaconItem = new javax.swing.JMenuItem();
action = new javax.swing.JMenu();
ajoutNAOH = new javax.swing.JMenuItem();
ajoutNACL = new javax.swing.JMenuItem();
ajoutNAOHNACL = new javax.swing.JMenuItem();
ajoutFeno = new javax.swing.JMenuItem();
affichePH = new javax.swing.JMenuItem();
vanett = new javax.swing.JMenu();
ouvre = new javax.swing.JMenuItem();
deminue = new javax.swing.JMenuItem();
augmente = new javax.swing.JMenuItem();
ferme = new javax.swing.JMenuItem();
reouvre = new javax.swing.JMenuItem();
jMenu1.setText("File");
nouveau.setText("Nouveau");
jMenu1.add(nouveau);
comren.setText("Compte rendu");
comren.addActionListener(this);
jMenu1.add(comren);
quit.setText("Quitter");
jMenu1.add(quit);
jMenuBar1.add(jMenu1);
materielItem.setText("Matériels");
buretteItem.setText("burette de 50 ml");
buretteItem.addActionListener(this);
materielItem.add(buretteItem);
flaconItem.setText("flacon erlenmeyer de 100 ml");
flaconItem.addActionListener(this);
materielItem.add(flaconItem);
jMenuBar1.add(materielItem);
action.setText("Actions");
ajoutNAOH.setText("Ajouter 50 ml de NAOH");
ajoutNAOH.addActionListener(this);
action.add(ajoutNAOH);
ajoutNACL.setText("Ajouter 35 ml de HCL");
ajoutNACL.addActionListener(this);
action.add(ajoutNACL);
ajoutFeno.setText("Ajouter 2 gouttes de fénolphtaléine(indicateur)");
ajoutFeno.addActionListener(this);
action.add(ajoutFeno);
affichePH.setText("Afficher le PH-métre");
affichePH.addActionListener(this);
action.add(affichePH);
vanett.setText("Vanette");
ouvre.setText("Ouvrir");
ouvre.addActionListener(this);
vanett.add(ouvre);
deminue.setText("Déminuer");
deminue.addActionListener(this);
vanett.add(deminue);
augmente.setText("Augmenter");
augmente.addActionListener(this);
vanett.add(augmente);
ferme.setText("Fermer");
ferme.addActionListener(this);
vanett.add(ferme);
reouvre.setText("Réouvrir");
reouvre.addActionListener(this);
vanett.add(reouvre);
action.add(vanett);
jMenuBar1.add(action);
setJMenuBar(jMenuBar1);
jPanel=new JPanel();
jPanel.setSize(1050, 750);
jPanel.setLayout(null);
jPanel1=new JPanel();
jPanel1.setBackground(Color.white);
jPanel1.setBounds(5,5,600, 600);
jPanel1.setLayout(null);
jPanel1.setBorder(BorderFactory.createTitledBorder(""));
jPanel.add(jPanel1);
this.add(jPanel);
flacon=new Flacon();
jPanel1.add(flacon);
burette=new Burette();
jPanel1.add(burette);
ph=new PHLbl();
PHmet.add(ph);
}
public void setUrl(String tmp){
url=tmp;
}
public String getUrl( ){
return url;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(flaconItem)){
txt1="image/burette/burette.png";
burette.setIma(txt1);
burette.setBounds(230,150,60, 280);
burette.repaint();
txt="image/flacon/flacon.png";
flacon.setIm(txt);
flacon.setBounds(200,430,105, 136);
flacon.repaint();
flacon.setVisible(true);
flaconItem.setEnabled(false);
action.setEnabled(true);
ajoutNACL.setEnabled(true);
materielItem.setEnabled(false);
}
}
class Flacon extends Panel{
public Flacon(){
}
public void paint(Graphics g)
{
super.paint(g);
txt=getIm();
base=getCodeBase();
iconn=getImage(base,txt);
g.drawImage(iconn, 20, 20, this);
}
public String getIm(){
return txt;}
public void setIm(String im) {
txt=im;
}}
class Burette extends Panel{
public Burette(){
}
public void paint(Graphics g)
{ super.paint(g);
txt=getIma();
bases=getCodeBase();
icon=getImage(bases,txt);
g.drawImage(icon, 20, 20, this);
}
public String getIma(){
return txt;}
public void setIma(String im) {
txt=im;
}
}
}
Afficher la suite