IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

conflit static <> repaint()


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 252
    Par défaut conflit static <> repaint()
    Bonjour

    voici ma classe

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
    public class graph extends JPanel{
     
    	static List<point> T=new ArrayList<point>();
     
    	static double angle;
     
        static void avancerCar() {
    		try {
    			carCourant = (char) System.in.read();
    		} catch (java.io.IOException e) {
    		}
    	}
     
        static void lireExpression() throws InterruptedException{
     
        	if (carCourant=='f'){avancerCar();lireDeplacement();}
        	else if (carCourant=='r'){avancerCar();lireRotation();}
        	else throw new Error (" Carac inattendu : ");
     
        }
     
        static void lireDeplacement() throws InterruptedException{
        	if (Character.isDigit(carCourant)){T.add(new point(carCourant*Math.cos(angle),carCourant*Math.sin(angle)));avancerCar();}
        	else throw new Error (" Carac inattendu : ");
        }
     
        static void lireRotation() throws InterruptedException{
        	if(Character.isDigit(carCourant)){angle+=(int)(carCourant);avancerCar();} 
        	else throw new Error (" Carac inattendu : ");
        }
     
        public void paint(Graphics g){
     
    		g.drawString("bonjour", 100, 100);
    		if (T.size()>1){
    			for (int i=0;i<T.size()-1;i++){
    				g.drawLine(T.get(i).abs, T.get(i).ord, T.get(i+1).abs-T.get(i).abs, T.get(i+1).ord-T.get(i).ord);
    			}
    		}
    	}
     
     
    	public static void main(String[] args) throws InterruptedException {
    		lex2.avancerCar () ; 
    		avancerCar() ; // initialisation du car courant
    		T.add(new point(0,0));
     
    		while (carCourant != ';'){ 
    			lireExpression();
     
    		}
    		for (int i=0;i<T.size();i++){
    			System.out.println(T.get(i).abs+".."+T.get(i).ord);
    		}
    	}
     
    }
     
    class point{
    	int abs,ord;
    	public point(double a,double o){abs=(int) (250+a);ord=(int) (250+o);}
    }
    à tester avec f4r5f5 dans la console d'entrée
    par exemple

    Le but est que ça s'actualise au fur et a mesure qu'on ajoute des points
    mais impossible de glisser des repaint() dans les méthodes qui sont STATIC

    comment faire SVP?

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 252
    Par défaut
    bon j'espere que j'ai été assez clair
    sinon demandez moi

    je pense qu'il faut creer une Image bufferisée ou pas et ensuite la dessinée dans le paint()

    il devrait tracer 2 petits segments
    mais ça marche pas

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.swing.JApplet;
     
     
     
    public class projet extends JApplet{
     
    	static List<point> T=new ArrayList<point>();
     
    	static double angle;
    	static char carCourant;
     
    	Image img;
     
        static void avancerCar() {
    		try {
    			carCourant = (char) System.in.read();
    		} catch (java.io.IOException e) {
    		}
    	}
     
        static void lireExpression() throws InterruptedException{
     
        	if (carCourant=='f'){avancerCar();lireDeplacement();}
        	else if (carCourant=='r'){avancerCar();lireRotation();}
        	else throw new Error (" Carac inattendu : ");
     
        }
     
        static void lireDeplacement() throws InterruptedException{
        	if (Character.isDigit(carCourant)){T.add(new point(Integer.parseInt(carCourant+"")*Math.cos(angle),Integer.parseInt(carCourant+"")*Math.sin(angle)));avancerCar();}
        	else throw new Error (" Carac inattendu : ");
        }
     
        static void lireRotation() throws InterruptedException{
        	if(Character.isDigit(carCourant)){angle+=Integer.parseInt(carCourant+"");avancerCar();} 
        	else throw new Error (" Carac inattendu : ");
        }
     
        public void init(){    	
        	img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
        	Graphics g = img.getGraphics();
     
        	g.drawString("bonjour", 100, 100);
        	if (T.size()>1){g.setColor(Color.blue);
    			for (int i=0;i<T.size()-1;i++){
    				g.drawLine(T.get(i).abs, T.get(i).ord, T.get(i+1).abs-T.get(i).abs, T.get(i+1).ord-T.get(i).ord);
    			}
    		}
        	paint (g);
        }
     
        public void paint(Graphics g){
        	if (img != null)g.drawImage(img, 0, 0, this);
    	}
     
     
    	public static void main(String[] args) throws InterruptedException {
     
    		avancerCar() ; // initialisation du car courant
    		T.add(new point(0,0));
     
    		while (carCourant != ';'){ 
    			lireExpression();
     
    		}
    		for (int i=0;i<T.size();i++){
    			System.out.println(T.get(i).abs+".."+T.get(i).ord);
    		}
    	}
     
    }
    class point{
    	int abs,ord;
    	public point(double a,double o){abs=(int) (250+a);ord=(int) (250+o);}
    }
    tester avec f5r5f5; dans la console d'entrée

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 252
    Par défaut
    j'ai changé des choses ça marche à peu pres

    merci d'avance si vous pouvez m'aider

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.swing.JApplet;
     
     
     
    public class projet extends JApplet {
     
    	static List<point> T=new ArrayList<point>();
     
    	static double angle;
    	static char carCourant;
     
    	Image img;
     
        static void avancerCar() {
    		try {
    			carCourant = (char) System.in.read();
    		} catch (java.io.IOException e) {
    		}
    	}
     
        static void lireExpression() throws InterruptedException{
     
        	if (carCourant=='f'){avancerCar();lireDeplacement();}
        	else if (carCourant=='r'){avancerCar();lireRotation();}
        	else throw new Error (" Carac inattendu : ");
     
        }
     
        static void lireDeplacement() throws InterruptedException{
        	if (Character.isDigit(carCourant)){T.add(new point(Integer.parseInt(carCourant+"")*Math.cos(angle),Integer.parseInt(carCourant+"")*Math.sin(angle)));avancerCar();}
        	else throw new Error (" Carac inattendu : ");
        }
     
        static void lireRotation() throws InterruptedException{
        	if(Character.isDigit(carCourant)){angle+=Integer.parseInt(carCourant+"");avancerCar();} 
        	else throw new Error (" Carac inattendu : ");
        }
     
        public void init(){   
     
     
        	avancerCar() ; // initialisation du car courant
        	T.add(new point(0,0));
        	while (carCourant != ';'){ 
    			try {
    				lireExpression();
    			} catch (InterruptedException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
     
    		}
    		for (int i=0;i<T.size();i++){
    			System.out.println(T.get(i).abs+".."+T.get(i).ord);
    		}
     
        }
     
     
     
        public void paint(Graphics g){
        	g.drawString("bonjour", 100, 100);
        	if (T.size()>1){g.setColor(Color.blue);
    			for (int i=0;i<T.size()-1;i++){
    				g.drawLine(T.get(i).abs, T.get(i).ord, T.get(i+1).abs-T.get(i).abs, T.get(i+1).ord-T.get(i).ord);
    			}
    		}
    	}
     
     
     
    }
     class point{
    	int abs,ord;
    	public point(double a,double o){abs=(int) (250+a);ord=(int) (250+o);}
    }

  4. #4
    Membre Expert
    Avatar de muad'dib
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2003
    Messages
    1 013
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2003
    Messages : 1 013
    Par défaut
    Il ne faut pas déclarer les méthodes et attributs statique à moins que tu saches ce que tu fais.

    Pour ton problème, voici un code qui devrait t'aider
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public class Test extends JApplet {
     
       public void paint(Graphics g) {
          g.drawString("Hello world", 50, 50);
       }
     
       public static void main(String args[]) {
          new Test();
       }
    }

Discussions similaires

  1. Conflit repaint/socket en attente (2)
    Par Dubphonic dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 23/03/2010, 12h25
  2. Réponses: 10
    Dernier message: 01/09/2009, 14h59
  3. Réponses: 2
    Dernier message: 01/06/2006, 14h36
  4. [Technique] Conflits entre plusieurs requêtes
    Par Neowile dans le forum Décisions SGBD
    Réponses: 3
    Dernier message: 24/03/2003, 09h37
  5. les variables globales static
    Par gRRosminet dans le forum C
    Réponses: 8
    Dernier message: 27/04/2002, 08h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo