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 :

Interface graphique supermarché : NullPointerException


Sujet :

Java

  1. #1
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut Interface graphique supermarché : NullPointerException
    Bonjour,
    je suis débutant en java et je voudrais faire une interface graphique comme celle ci
    aussi il faut que je récupéré le poids d'un balance en port série pour calculer le prix
    j'ai ce code la mais il fonctionne toujours 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
    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
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.util.Locale;
    import java.sql.*;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException.*;
     
    class FenText extends JFrame implements ActionListener
    {
        private double prixx;
        private JButton brocoli,carotte,chouxfleur,courgette,haricot,poivron,pomme,orange,banane,kiwi,peche,fraise,balance;
        private JLabel affichage;
        private JPanel pano;
        private JPanel container = new JPanel();
        private JTextField poids;
        private JTextField prix;
     
        public FenText()
        {
        JFrame f= new JFrame();
        f.setSize(1100, 620);
        f.setTitle("Legumes&Freuits");
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     
     
        pano = new JPanel(new GridLayout(4,22));
        affichage = new JLabel();
        pano.add(brocoli);
        pano.add(carotte);
        pano.add(chouxfleur);
        pano.add(courgette);
        pano.add(haricot);
        pano.add(poivron);
        pano.add(pomme);
        pano.add(orange);
        pano.add(banane);
        pano.add(kiwi);
        pano.add(peche);
        pano.add(fraise);
        pano.add(balance);
        add(pano);
        setVisible(true);
     
     
        JPanel top = new JPanel();
        Font police = new Font("Arial", Font.BOLD,14);
        poids.setFont(police);
        poids.setPreferredSize(new Dimension(180,50));
        top.add(new JLabel("POIDS (g)"));
        top.add(poids);
        prix.setFont(police);
        prix.setPreferredSize(new Dimension(180,50));
        top.add(new JLabel ("PRIX (€)"));
        top.add(prix);
                //Container container = null;
        container.add(top, BorderLayout.CENTER);
        this.setContentPane(container);
        this.setVisible(true);
     
        ImageIcon BrocoliImage = new ImageIcon("/home/chebbah/brocoli.jpg");
        ImageIcon CarotteImage = new ImageIcon("/home/chebbah/carotte.jpg");
        ImageIcon ChouxFleurImage = new ImageIcon("/home/chebbah/chouxfleur.jpg");
        ImageIcon CourgetteImage = new ImageIcon("/home/chebbah/courgette.jpg");
        ImageIcon HaricotImage = new ImageIcon("/home/chebbah/haricot.jpg");
        ImageIcon PoivronImage = new ImageIcon("/home/chebbah/poivrons.jpg");
        ImageIcon PommeImage = new ImageIcon("/home/chebbah/pomme.jpg");
        ImageIcon OrangeliImage = new ImageIcon("/home/chebbah/orange.jpg");
        ImageIcon BananeImage = new ImageIcon("/home/chebbah/banane.jpg");
        ImageIcon KiwiImage = new ImageIcon("/home/chebbah/kiwi.jpg");
        ImageIcon PecheImage = new ImageIcon("/home/chebbah/peche.jpg");
        ImageIcon FraiseImage = new ImageIcon("/home/chebbah/fraise.jpg");
        ImageIcon BalanceImage = new ImageIcon("/home/chebbah/balance.jpg");
     
        brocoli =new JButton("<html>BROCOLI<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", BrocoliImage);
        carotte =new JButton("<html>CAROTTE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", CarotteImage);
        chouxfleur =new JButton("<html>CHOUXFLEUR<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", ChouxFleurImage);
        courgette =new JButton("<html>COURGETTE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", CourgetteImage);
        haricot =new JButton("<html>HARICOT<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", PoivronImage);
        poivron =new JButton("<html>POIVRON<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", HaricotImage);
        pomme =new JButton("<html>POMME<br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", PommeImage);
        orange =new JButton("<html>ORANGE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", OrangeliImage);
        banane =new JButton("<html>BANANE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", BananeImage);
        kiwi =new JButton("<html>KIWI<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", KiwiImage);
        peche =new JButton("<html>PECHE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", PecheImage);
        fraise =new JButton("<html>FRAISE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.98€/Kg</html>", FraiseImage);
        balance =new JButton("<html>CLIQUEZ ICI </html>",BalanceImage);
     
     
     
        brocoli.addActionListener(this);
        carotte.addActionListener (this);
        chouxfleur.addActionListener(this);
        courgette.addActionListener (this);
        haricot.addActionListener(this);
        poivron.addActionListener (this);
        pomme.addActionListener(this);
        orange.addActionListener (this);
        banane.addActionListener(this);
        kiwi.addActionListener(this);
        peche.addActionListener (this);
        fraise.addActionListener(this);
        balance.addActionListener(this);
     
     
    }
     
        @Override
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }
     
        public class FenetreLegum
        {
            public static void main (String args[])
            {
            FenText fen = new FenText();
            fen.pack();
            fen.setVisible(true);
            }
        }
    Merci.

    Nom : 15480665340419_111.png
Affichages : 299
Taille : 362,2 Ko

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 086
    Points : 7 997
    Points
    7 997
    Par défaut
    Citation Envoyé par lellouche99 Voir le message
    j'ai ce code la mais il fonctionne toujours pas
    C'est à dire ?

  3. #3
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Bonjour,
    il m'affiche ce problème :
    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl(Container.java:1095)
    at java.awt.Container.add(Container.java:419)
    at FenText.<init>(FenetreLegum.java:39)
    at FenetreLegum.main(FenetreLegum.java:138)

  4. #4
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 086
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 086
    Points : 7 997
    Points
    7 997
    Par défaut
    Ben quand tu fais
    brocoli est NULL puisque tu crée le bouton pour le brocoli après. (même chose pour tout les légumes).

  5. #5
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    Merci pour t'as remarque, j'ai ressui a le mettre fonctionner, maintenant il me reste de mettre la balance et de récupérer le poids

    Merci .
    Nom : prog.png
Affichages : 231
Taille : 141,5 Ko

  6. #6
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    j'ai fait l’interface graphique,mais j'ai réussi a récupérer le poids avec minicom mais je ne sais pas comment mettre le poids dans le programme java .

    aidez moi merci .
    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
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.util.Locale;
    import java.sql.*;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException.*;
     
    class FenText extends JFrame 
    {
        private double prixT;
        private JButton brocoli,carotte,chouxfleur,courgette,haricot,poivron,pomme,orange,banane,kiwi,peche,fraise,balance,annuler;
        private JPanel pan;
        private JTextField poids = new JTextField("  ");
        private JTextField prix  = new JTextField("  ");
     
        public FenText()
        {
     
        setSize(680, 680);//Définit sa taille : 680 pixels de large et 680 pixels de haut
        setTitle("Legumes & Freuits");//Définit un titre pour notre fenêtre
        setResizable(false);//pour la résolution de la fenetre ne sera pas modifiable 
        setLocationRelativeTo(null);//Pour mettre la fenetre au mileu d'ecran
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);////Termine le processus lorsqu'on clique sur la croix rouge
     
        pan = new JPanel();//creer un nouvelle panel
     
        poids.setPreferredSize(new Dimension(180,50));
        pan.add(new JLabel("POIDS (g)"));
        pan.add(poids);
     
        prix.setPreferredSize(new Dimension(180,50));
        pan.add(new JLabel ("PRIX (€)"));
        pan.add(prix);
     
     
     
    /******/
     
        ImageIcon BrocoliImage = new ImageIcon("brocoli4.png");
        ImageIcon PommeImage = new ImageIcon("pomme.png");
        ImageIcon BananeImage = new ImageIcon("banane.png");
        ImageIcon KiwiImage = new ImageIcon("kiwi.png");
        ImageIcon FraiseImage = new ImageIcon("fraise.png");
        ImageIcon PecheImage = new ImageIcon("peche.png");
        ImageIcon OrangeImage = new ImageIcon("orange.png");
        ImageIcon CourgetteImage = new ImageIcon("cougette.png");
        ImageIcon HaricotImage = new ImageIcon("haricot.png");
        ImageIcon PoivrontImage = new ImageIcon("poivron.png");
        ImageIcon CarotteiImage = new ImageIcon("carotte.png");
        ImageIcon ChouxfleurImage = new ImageIcon("chouxfleur.png");
        ImageIcon BlanceImage = new ImageIcon("balance.png");
        ImageIcon AnnulerImage = new ImageIcon("annuler.png");
     
     
     
     
    brocoli =new JButton("<html>BROCOLI<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.80€/Kg</html>",BrocoliImage);
     
    carotte =new JButton("<html>CAROTTE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.50€/Kg</html>",CarotteiImage);
    chouxfleur =new JButton("<html>CHOUXFLEUR<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.20€/Kg</html>",ChouxfleurImage);
    courgette =new JButton("<html>COURGETTE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.10€/Kg</html>",CourgetteImage);
    haricot =new JButton("<html>HARICOT<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.40€/Kg</html>",HaricotImage);
    poivron =new JButton("<html>POIVRON<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.60€/Kg</html>",PoivrontImage);
    pomme =new JButton("<html>POMME<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.00€/Kg</html>",PommeImage);
    orange =new JButton("<html>ORANGE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.50€/Kg</html>",OrangeImage);
    banane =new JButton("<html>BANANE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.99€/Kg</html>",BananeImage);
    kiwi =new JButton("<html>KIWI<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4.30€/Kg</html>",KiwiImage);
    peche =new JButton("<html>PECHE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.70€/Kg</html>",PecheImage);
    fraise =new JButton("<html>FRAISE<br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.90€/Kg</html>",FraiseImage);
    balance =new JButton("<html> Payer </html>",BlanceImage);
    annuler =new JButton("<html> Annuler </html>",AnnulerImage);
     
     
     
     
        pan.add(brocoli);        //ajoute le boutton dans le panel
        pan.add(carotte);
        pan.add(chouxfleur);
        pan.add(courgette);
        pan.add(haricot);
        pan.add(poivron);
        pan.add(pomme);
        pan.add(orange);
        pan.add(banane);
        pan.add(kiwi);
        pan.add(peche);
        pan.add(fraise);
        pan.add(balance);
        pan.add(annuler);
        setContentPane(pan); 
        }
     
     
    }
     
    public class FenetreLegum3
    {
            public static void main (String args[])
            {
            FenText fen = new FenText();
            fen.setVisible(true);
            }
    }

Discussions similaires

  1. Réponses: 2
    Dernier message: 29/03/2004, 18h29
  2. interface graphique utilisateur, que faut-il utiliser?
    Par Missvan dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 01/03/2004, 12h18
  3. Application multiplateforme avec interface graphique
    Par TNorth dans le forum Choisir un environnement de développement
    Réponses: 2
    Dernier message: 31/01/2004, 18h55
  4. [Kylix] Interface graphique pour lognes de commande linux
    Par lecharcutierdelinux dans le forum EDI
    Réponses: 6
    Dernier message: 29/08/2003, 10h20
  5. plugin interface graphique
    Par jocelyn dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 13/08/2003, 09h49

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