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

Langage Java Discussion :

problème generateur de codebarre code39


Sujet :

Langage Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    99
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 99
    Points : 49
    Points
    49
    Par défaut problème generateur de codebarre code39
    Bonjour ,
    Pouvez vous m'aider , j'ai un problème pour generer des codes barre en Code39 . Je m'explique , une chaine représente une suite de chiffre binaire Code39 . Lorsque je teste une ChaineSymbole cela marche mais lorsque j'essai de faire un code barre complet avec la methode paint de code39 cela ne marche pas :/
    Merci d'avance

    enum Epaisseur
    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
     
    import java.awt.Graphics;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author anthony
     */
    public enum Epaisseur {
     
        LARGE(6), ETROIT(3);
        int taille;
        final int hauteur = 100;
     
        private Epaisseur(int taille) {
            this.taille = taille;
        }
     
        public void dessineToi(Graphics e, int x, int y) {
            e.fillRect(x, y, this.taille, this.hauteur);
        }
    }
    Enum Nature
    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
     
    import java.awt.Color;
    import java.awt.Graphics;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author anthony
     */
    public enum Nature { 
        BARRE(Color.BLACK),ESPACE(Color.WHITE);
        Color couleur;
     
        private Nature(Color couleur){
            this.couleur=couleur;
        }
     
         public void dessineToi(Graphics e){
        e.setColor(this.couleur);
     
    }
    }

    Classe Symbole
    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
     
    import java.awt.Color;
    import java.awt.Graphics;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author anthony
     */
    public class Symbole {
     
        Epaisseur epaisseur;
        Nature nature;
     
        public Symbole(Epaisseur epaisseur, Nature nature) {
            this.nature = nature;
            this.epaisseur = epaisseur;
        }
     
        public String toString() {
            return "l'epaisseur est:" + this.epaisseur + " la nature est:" + this.nature;
        }
     
        public void dessineToi(Graphics e, int x, int y) {
            this.nature.dessineToi(e);
            this.epaisseur.dessineToi(e, x, y);
     
        }
     
        public String toValue() {
            if (this.epaisseur == epaisseur.LARGE) {
                return "1";
            }
            return "0";
        }
     
     
    }
    IteratorChaineSymbole
    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
     
    import java.util.Iterator;
    import java.util.NoSuchElementException;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author anthony
     */
    public class IteratorChaineSymbole implements Iterator<Symbole> {
        private ChaineSymbole chaineSymbole;
            private int indice = 0;
     
     
            public  IteratorChaineSymbole(ChaineSymbole symbole){
            this.chaineSymbole=symbole;
            this.indice=0;}
     
        @Override
        public boolean hasNext() {
            return indice < this.chaineSymbole.chaine.size();
        }
     
        @Override
        public Symbole next() {
             return this.chaineSymbole.chaine.get(indice++);
      }
     
        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public static void main(String[]args){
        ChaineSymbole chaine3 = new ChaineSymbole("10110011000001");
            Iterator it= new IteratorChaineSymbole(chaine3);
            while(it.hasNext()){
     
            System.out.println("ok"+it.next());}
        }
     
    }
    Classe Chaine Symbole
    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author anthony
     */
    import java.awt.Graphics;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.NoSuchElementException;
     
    public class ChaineSymbole {
     
        /*
         * To change this template, choose Tools | Templates
         * and open the template in the editor.
         */
        /**
         *
         * @author anthony
         */
        List<Symbole> chaine = new ArrayList();
     
        public ChaineSymbole(List<Symbole> chaine) {
            this.chaine = chaine;
        }
     
        public ChaineSymbole(Symbole... chaine) {
            List<Symbole> e1 = new LinkedList();
     
            for (int i = 0; i < chaine.length; i++) {
                e1.add(chaine[i]);
            }
            this.chaine = e1;
     
        }
     
        public ChaineSymbole(int... chaine) {
            System.out.println("Constructeur tableau entier");
            toSymbole(chaine);
     
        }
     
        public ChaineSymbole(String chaine) {
     
            int[] tab = new int[chaine.length()];
            for (int i = 0; i < chaine.length(); i++) {
                System.out.println(chaine.charAt(i));
                String m = String.valueOf(chaine.charAt(i));
                tab[i] = Integer.parseInt(m);
                System.out.println("tab[i]:"+tab[i]);
     
            }
            toSymbole(tab);
     
     
        }
     
        private void toSymbole(int[] chaine) {
            Epaisseur e; Nature n;
            for (int i = 0; i < chaine.length; i++) {
               if(chaine[i]==0){e=Epaisseur.ETROIT;}
               else{e=Epaisseur.LARGE;}
               if(i%2!=0){n=Nature.ESPACE;}
               else{n=Nature.BARRE;}
            this.add(new Symbole(e,n));
            }
     
        }
     
        public int size() {
            return this.chaine.size();
        }
     
        public Symbole get(int indice) {
            return this.chaine.get(indice);
        }
     
        public void add(Symbole chaine) {
            /*if (this.chaine.size() < 10) {
                //System.out.println(chaine);
     
                this.chaine.add(chaine);
            } else {
                System.err.print("Ajout impossible");
            }*/
            this.chaine.add(chaine);
        }
     
        public int dessineToi(Graphics e, int x) {
     
            int y = 150;
            Iterator it = new IteratorChaineSymbole(this);
            while (it.hasNext()) {
     
                Symbole e1 = (Symbole) it.next();
                e1.dessineToi(e, x, y);
                x += e1.epaisseur.taille;
    System.out.println("valeur de x:"+x);
            }
            return x;
        }
     
        String toValue() {
            StringBuilder value = new StringBuilder();
            for (Symbole symbole : chaine) {
                System.out.println(symbole);
                value.append(symbole.toValue());
            }
            return value.toString();
        }
     
        static public void main(String[] args) {
            ChaineSymbole chaine3 = new ChaineSymbole("101100111");
            for(Symbole element : chaine3.chaine){
     
            System.out.println(element);}
     
        }
    }
    Classe Code39
    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
     
    import java.awt.Graphics;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author anthony
     */
    public class Code39 {
     
        static public HashMap<String, ChaineSymbole> code39 = new HashMap(39);
        static Symbole s1 = new Symbole(Epaisseur.ETROIT, Nature.ESPACE);
     
        static {
            code39.put("A", new ChaineSymbole(1, 0, 0, 0, 0, 1, 0, 0, 1));
            code39.put("B", new ChaineSymbole(0, 0, 1, 0, 0, 1, 0, 0, 1));
            code39.put("C", new ChaineSymbole(1, 0, 1, 0, 0, 1, 0, 0, 0));
            code39.put("D", new ChaineSymbole(0, 0, 0, 0, 1, 1, 0, 0, 1));
            code39.put("E", new ChaineSymbole(1, 0, 0, 0, 1, 1, 0, 0, 0));
            code39.put("F", new ChaineSymbole(0, 0, 1, 0, 1, 1, 0, 0, 0));
            code39.put("G", new ChaineSymbole(0, 0, 0, 0, 0, 1, 1, 0, 1));
            code39.put("H", new ChaineSymbole(1, 0, 0, 0, 0, 1, 1, 0, 0));
            code39.put("I", new ChaineSymbole(0, 0, 1, 0, 0, 1, 1, 0, 0));
            code39.put("J", new ChaineSymbole(0, 0, 0, 0, 1, 1, 1, 0, 0));
            code39.put("K", new ChaineSymbole(1, 0, 0, 0, 0, 0, 0, 1, 1));
            code39.put("L", new ChaineSymbole(0, 0, 1, 0, 0, 0, 0, 1, 1));
            code39.put("M", new ChaineSymbole(1, 0, 1, 0, 0, 0, 0, 1, 0));
            code39.put("N", new ChaineSymbole(0, 0, 0, 0, 1, 0, 0, 1, 1));
            code39.put("O", new ChaineSymbole(1, 0, 0, 0, 1, 0, 0, 1, 0));
            code39.put("P", new ChaineSymbole(0, 0, 1, 0, 1, 0, 0, 1, 0));
            code39.put("Q", new ChaineSymbole(0, 0, 0, 0, 0, 0, 1, 1, 1));
            code39.put("R", new ChaineSymbole(1, 0, 0, 0, 0, 0, 1, 1, 0));
            code39.put("S", new ChaineSymbole(0, 0, 1, 0, 0, 0, 1, 1, 0));
            code39.put("T", new ChaineSymbole(0, 0, 0, 0, 1, 0, 1, 1, 0));
            code39.put("U", new ChaineSymbole(1, 1, 0, 0, 0, 0, 0, 0, 1));
            code39.put("V", new ChaineSymbole(0, 1, 1, 0, 0, 0, 0, 0, 1));
            code39.put("W", new ChaineSymbole(1, 1, 1, 0, 0, 0, 0, 0, 0));
            code39.put("X", new ChaineSymbole(0, 1, 0, 0, 1, 0, 0, 0, 1));
            code39.put("Y", new ChaineSymbole(1, 1, 0, 0, 1, 0, 0, 0, 0));
            code39.put("Z", new ChaineSymbole(0, 1, 1, 0, 1, 0, 0, 0, 0));
            code39.put("0", new ChaineSymbole(0, 0, 0, 1, 1, 0, 1, 0, 0));
            code39.put("1", new ChaineSymbole(1, 0, 0, 1, 0, 0, 0, 0, 1));
            code39.put("2", new ChaineSymbole(0, 0, 1, 1, 0, 0, 0, 0, 1));
            code39.put("3", new ChaineSymbole(1, 0, 1, 1, 0, 0, 0, 0, 0));
            code39.put("4", new ChaineSymbole(0, 0, 0, 1, 1, 0, 0, 0, 1));
            code39.put("5", new ChaineSymbole(1, 0, 0, 1, 1, 0, 0, 0, 0));
            code39.put("6", new ChaineSymbole(0, 0, 1, 1, 1, 0, 0, 0, 0));
            code39.put("7", new ChaineSymbole(0, 0, 0, 1, 0, 0, 1, 0, 1));
            code39.put("8", new ChaineSymbole(1, 0, 0, 1, 0, 0, 1, 0, 0));
            code39.put("9", new ChaineSymbole(0, 0, 1, 1, 0, 0, 1, 0, 0));
            code39.put(" ", new ChaineSymbole(0, 1, 1, 0, 0, 0, 1, 0, 0));
            code39.put("-", new ChaineSymbole(0, 1, 0, 0, 0, 0, 1, 0, 1));
            code39.put("$", new ChaineSymbole(0, 1, 0, 1, 0, 1, 0, 0, 0));
            code39.put("%", new ChaineSymbole(0, 0, 0, 1, 0, 1, 0, 1, 0));
            code39.put(".", new ChaineSymbole(1, 1, 0, 0, 0, 0, 1, 0, 0));
            code39.put("/", new ChaineSymbole(0, 1, 0, 1, 0, 0, 0, 1, 0));
            code39.put("+", new ChaineSymbole(0, 1, 0, 0, 0, 1, 0, 1, 0));
            code39.put("*", new ChaineSymbole(0, 1, 0, 0, 1, 0, 1, 0, 0));
     
        }
     
        static public String toBinary(String elements) {
            System.out.print("toto");
            System.out.print(code39.get(elements).toValue());
            return code39.get(elements).toValue();
        }
     
        /* static public List toBinaryList(String elements) {
        String valeur = code39.get(elements).toValue();
        String tab[] = valeur.split("");
        List e1 = new ArrayList();
        for (String element : tab) {
        e1.add(element);
        
        }
        return e1;
        
        
        }*/
        static public String toChar(String binary) {
            Set cles = code39.keySet();
            Iterator it = cles.iterator();
            while (it.hasNext()) {
                Object cle = it.next();
                ChaineSymbole valeur = code39.get(cle);
                if (valeur.toValue().equals(binary)) {
                    return cle.toString();
                }
     
            }
            return "impossible";
        }
     
        static public String toCode(String alpha) {
            StringBuilder value = new StringBuilder();
            if (!alpha.startsWith("*")) {
                alpha = "*" + alpha;
            }
            char tab[] = alpha.toCharArray();
            for (char element : tab) {
                value.append(Code39.toBinary(String.valueOf(element)));
     
            }
     
     
     
            if (!alpha.endsWith("*")) {
                value.append(Code39.toBinary("*"));
            }
            return value.toString();
        }
     
        static public void paint(Graphics e, String message) {
            int x=0;
            ChaineSymbole painted[] = new ChaineSymbole[message.length()];//tableau de chaineSymbole
            System.out.println("le message: " + message.length());
     
            for (int i = 0; i < message.length(); i++) { //tant que i<message
                System.out.println("Le code est:" + Code39.toBinary(String.valueOf(message.charAt(i))));//Code ok!
                painted[i] = new ChaineSymbole(Code39.toBinary(String.valueOf(message.charAt(i))));
                x+=painted[i].dessineToi(e, x);
     
                s1.dessineToi(e, x, 150);
                x+=s1.epaisseur.taille;
                System.out.println(x);
     
            }
     
     
        }
     
        static public void main(String[] args) {
     
            System.out.println(Code39.toCode("MACHAINE"));
        }
    }
    Classe TestApplet
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
     
    /**
     *
     * @author anthony
     */
    public class TestApplet extends Applet {
     
        /**
         * Initialization method that will be called after the applet is loaded
         * into the browser.
         */
        public void init() {
          setBackground(Color.white);
            setSize(750, 250);  // TODO start asynchronous download of heavy resources
        }
     
        public void paint(Graphics g) {
            super.paint(g);
     
     
            //ChaineSymbole chaine3 = new ChaineSymbole("10110011000001");
            //chaine3.dessineToi(g, 150);-> OK
            //Iterator it= new IteratorChaineSymbole(chaine3);
            //while(it.hasNext()){
     
            //System.out.println("ok"+it.next());}
     
            //Code39.paint(g, "A"); 
     
     
           Code39.paint(g,"AB");
            //g.fillRect(WIDTH, WIDTH, WIDTH, WIDTH); creer une figure pleine selon la couleur
     
        }
    }
    // TODO overwrite start(), stop() and destroy() methods
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Problème lecture codebarre
    Par Higgins dans le forum Langage
    Réponses: 6
    Dernier message: 20/09/2013, 07h19
  2. Problème de generateur de clé primaire
    Par cgone dans le forum Bases de données
    Réponses: 6
    Dernier message: 30/11/2006, 17h47
  3. Problème d'installation oracle 8.1.7 sous NT
    Par Anonymous dans le forum Installation
    Réponses: 7
    Dernier message: 02/08/2002, 14h18
  4. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10
  5. Réponses: 6
    Dernier message: 25/03/2002, 21h11

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