[Java2D] Ecrire dans un carre
Bonjour,
Mon application est un éditeur graphique modéliser un système sous forme de réseau de Petri (Carre, cercle, flèche, jeton).
Quand je dessine un carré (tâche) il faut ajouter un nom pour cette tâche à l'intérieur de cet carré.
problème:
Avec mon code tous les tache prend le nom de la dernière tâche insérer!!!
partie de mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
public void affiche(Graphics g){
Graphics2D g2 = (Graphics2D) g;
super.affiche(g);
g2.setStroke(wideStroke);
g.drawPolygon( this.toPolygon());
PoliceNomTache = new Font("Dialog", Font.BOLD, 11);
g.setFont(PoliceNomTache);
g.drawString(DialogueEtiquette.getTexte(),tab[0].rendreX()+3,tab[0].rendreY()-20);
return;
} |
tab[i] contient des points pour dessiner un carré.
(Ces points sont insérer par la souris: e.getX() , e.getY() )
Classe DialogueEtiquette:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class DialogueEtiquette extends JDialog implements ActionListener {
private static JTextField champDeTexte;
DialogueEtiquette(String titre) {
super((JFrame) null, titre, true);
JButton bouton = new JButton("OK");
bouton.addActionListener(this);
champDeTexte = new JTextField(20);
champDeTexte.addActionListener(this);
JPanel panneau = new JPanel();
panneau.add(bouton);
getContentPane().add(new JLabel("Donnez l'étiquette"), BorderLayout.NORTH);
getContentPane().add(champDeTexte, BorderLayout.CENTER);
getContentPane().add(panneau, BorderLayout.SOUTH);
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
.getScreenSize();
setLocation((screenSize.width-getSize().width)/2,(screenSize.height-getSize().height)/2);
setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
dispose();
}
public static String getTexte() {
return champDeTexte.getText();
}
} |
bug:
merci: