A voir également:
- Programmation Java problème sous paint
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Paint net - Télécharger - Dessin & Illustration
- Tux paint - Télécharger - Dessin & Illustration
- Paint 3d mac - Télécharger - Dessin & Illustration
1 réponse
Phortitou
Messages postés
221
Date d'inscription
jeudi 6 novembre 2008
Statut
Membre
Dernière intervention
4 décembre 2011
27
20 août 2010 à 13:46
20 août 2010 à 13:46
Cette portion de code ne suffit pas pour trouver ton erreur. Il faudrait savoir ce qu'est ton viewPanel et comment marchent tes tools.
20 août 2010 à 13:49
Voici l'exemple d'un tool en l'occurence CircleTool:
public class CircleTool extends Tool{
public CircleTool(ViewPanel viewPanel){
super(viewPanel);
}
protected View createView(){
double width = this.getEnd().getX()-this.getStart().getX();
double height = this.getEnd().getY()-this.getStart().getY();
double X = this.getStart().getX();
double Y = this.getStart().getY();
double size = 0;
if( Math.abs(width)< Math.abs(height)){
size = Math.abs(height);
if(width<0)
X = X-size;
if(height<0)
Y = Y-size;
}
else{
size = Math.abs(width);
if(width<0)
X = X-size;
if(height<0)
Y = Y-size;
}
Shape circle = new Circle(X,Y,size);
circle.setLineColour(this.getViewPanel().getCurrentDrawColour());
View view = new View(circle);
return view;
}
}
je sais pas si çà peut t'aider?
Modifié par Phortitou le 20/08/2010 à 13:56
20 août 2010 à 13:58
public class ViewPanel extends javax.swing.JPanel{
protected static final int DEFAULT_WIDTH=200;
/*définit la hauteur par défaut*/
protected static final int DEFAULT_HEIGHT=800;
//définit la largeur par défaut
protected static final Color DEFAULT_BACKGROUND_COLOUR=new Color (1);
//définuit la couleur de fond par défaut
protected static final Color DEFAULT_DRAW_COLOUR=new Color (9);
//définit la couleur d'écriture par défaut
private BasicFrame mainFrame;
private Color currentDrawColour = DEFAULT_DRAW_COLOUR;
private Tool currentTool;
private ArrayList<View> views= new ArrayList<View>();
private Dimension dim;
//Constructeur par défaut permettant de définir la dimension,la couleur de fond,la couleur du tracé de la zone de dessin(ViewPanel)
public ViewPanel(int width, int height, Color backgroundColour){
Dimension dim = new Dimension(width, height);
this.setPreferredSize(dim);
this.setBackground(backgroundColour);
setCurrentDrawColour(DEFAULT_DRAW_COLOUR);
}
//Méthode permettant d'ajouter une vue
public void addView(View view){
views.add(view);
//pourquoi this.add(view) ne suffit pas?
}
//Retourne la BasicFrame dans lequel se trouve cet objet.
public BasicFrame getBasicFrame(){
return this.mainFrame;
//Retourne la BasicFrame dans lequel se trouve cet objet
//Entraine la créataion de private BasicFrame mainFrame
}
//Méthode permettant de retourner la couleur du tracé
public Color getCurrentDrawColour(){
return this.currentDrawColour;
}
//Méthode permettant de retourner la vue
public ArrayList<View> getViews(){
return views;
}
//Méthode permettant de peindre les différentes vues
public void paint(Graphics g){
super.paint(g);
java.awt.Graphics2D g2D = (Graphics2D)g ; // Le paramètre g de la méthode paint est converti en un Graphics2D
int nbreDeViews;
if(this.views !=null)
nbreDeViews = this.views.size();
else
nbreDeViews = 0;
int i;
for(i = 0 ; i < nbreDeViews ; i++)
this.views.get(i).display(g2D);
}
//Méthode permettant de définir la BasicFrame dans laquelle se trouve la ViewPanel
public void setBasicFrame(BasicFrame mainFrame){
this.mainFrame = mainFrame;
}
//Méthode permettant de définir la couleur de fond
public void setCurrentDrawColour(Color colour){
this.currentDrawColour=colour;
}
//Méthode permettant de retourner l'outil utilisé
public Tool getCurrentTool(){
return this.currentTool;
}
//Méthode permettant de définir l'outil utilisé
public void setCurrentTool(Tool tool){
currentTool=tool;
}
//Méthode permettant de définir un nouvel ensemble de vue
public void setViews(ArrayList<View> views){
this.views = views;
}
public void setDim(Dimension dim) {
this.dim = dim;
}
public Dimension getDim() {
return dim;
}
}
20 août 2010 à 14:27
Est il possible de faire en sorte que le current tool soit réinitialisé pour ne pas garder l'action précedente?
20 août 2010 à 17:56