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

Agents de placement/Fenêtres Java Discussion :

JFrame utilisation du PaintComponent


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Par défaut JFrame utilisation du PaintComponent
    Bonsoir à tous,

    J'ai un petit souci, je débute dans les IMH, j'aimerais dessiner une matrice via le PaintComponent() et l'affecter à un Panel en particulier, je ne sais pas trop comment m'y prendre voici ce que j'ai fais, pour le moment le PaintComponent() ne s'applique pas du tout...

    Voici le code :

    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
    public class Fenetre extends JFrame{
        private JPanel accueil = new JPanel();
        private JPanel page1 = new JPanel();
        private JLabel label = new JLabel("TEST");
        private JButton b = new JButton ("Jouer");
     
        public Fenetre(){
     
            this.setTitle("TEST");
            this.setSize(1000,800);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
     
            accueil.setLayout(null);
            accueil.setBackground(Color.white);
     
            Font police = new Font("Arial", Font.BOLD, 22);
            label.setFont(police);
            label.setForeground(Color.ORANGE);
            label.setBounds(this.getWidth()/2-75, this.getHeight()/2-105, 200, 75);
     
            b.addActionListener(new BoutonListener());
            b.setForeground(Color.blue);
            b.setBackground(Color.orange);
            b.setBounds(this.getWidth()/2-75, this.getHeight()/4*3, 100, 60);
     
            accueil.add(b);
            accueil.add(label);
            this.setContentPane(accueil);
     
        }
     
     
        public void changerMenu(){
            this.setContentPane(this.page1);
            this.revalidate();
            this.repaint();
        }
     
        public void PaintComponent(Graphics g){
            System.out.println("Dans paint componenent");
     
            //Colonnes
            g.drawLine(this.getWidth()/15,0,this.getWidth()/15,this.getHeight());
            g.drawLine(this.getWidth()/15*2,0,this.getWidth()/15*2,this.getHeight());
            g.drawLine(this.getWidth()/15*3,0,this.getWidth()/15*3,this.getHeight());
            g.drawLine(this.getWidth()/15*4,0,this.getWidth()/15*4,this.getHeight());
            g.drawLine(this.getWidth()/15*5,0,this.getWidth()/15*5,this.getHeight());
            g.drawLine(this.getWidth()/15*6,0,this.getWidth()/15*6,this.getHeight());
            g.drawLine(this.getWidth()/15*7,0,this.getWidth()/15*7,this.getHeight());
            g.drawLine(this.getWidth()/15*8,0,this.getWidth()/15*8,this.getHeight());
            g.drawLine(this.getWidth()/15*9,0,this.getWidth()/15*9,this.getHeight());
            g.drawLine(this.getWidth()/15*10,0,this.getWidth()/15*10,this.getHeight());
            g.drawLine(this.getWidth()/15*11,0,this.getWidth()/15*11,this.getHeight());
            g.drawLine(this.getWidth()/15*12,0,this.getWidth()/15*12,this.getHeight());
            g.drawLine(this.getWidth()/15*13,0,this.getWidth()/15*13,this.getHeight());
     
            //Lignes
            g.drawLine(0, this.getHeight()/15, this.getWidth(), this.getHeight()/15);
            g.drawLine(0, this.getHeight()/15*2, this.getWidth(), this.getHeight()/15*2);
            g.drawLine(0, this.getHeight()/15*3, this.getWidth(), this.getHeight()/15*3);
            g.drawLine(0, this.getHeight()/15*4, this.getWidth(), this.getHeight()/15*4);
            g.drawLine(0, this.getHeight()/15*5, this.getWidth(), this.getHeight()/15*5);
            g.drawLine(0, this.getHeight()/15*6, this.getWidth(), this.getHeight()/15*6);
            g.drawLine(0, this.getHeight()/15*7, this.getWidth(), this.getHeight()/15*7);
            g.drawLine(0, this.getHeight()/15*8, this.getWidth(), this.getHeight()/15*8);
            g.drawLine(0, this.getHeight()/15*9, this.getWidth(), this.getHeight()/15*9);
            g.drawLine(0, this.getHeight()/15*10, this.getWidth(), this.getHeight()/15*10);
            g.drawLine(0, this.getHeight()/15*11, this.getWidth(), this.getHeight()/15*11);
            g.drawLine(0, this.getHeight()/15*12, this.getWidth(), this.getHeight()/15*12);
            g.drawLine(0, this.getHeight()/15*13, this.getWidth(), this.getHeight()/15*13);
            g.drawLine(0, this.getHeight()/15*14, this.getWidth(), this.getHeight()/15*14);
     
            page1.paint(g);
     
        }
     
        class BoutonListener implements ActionListener{
     
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                Fenetre.this.changerMenu();
            }
     
        }
    Donc voila, ma page d'accueil s'affiche très bien mais lorsque j'atteins ma deuxieme page via le bouton, celle ci est vide.

    Merci par avance

  2. #2
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Ben tu dois créer un sous classe de JPanel où tu redéfini paintComponent et dedans tu met son code de desssin. Par contre tu ne dois pas redéfinir le paintComponent de la JFrame du coup.

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Par défaut
    Comme ceci :

    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
    class Page extends JPanel {
     
     
    		@Override
    		public void paintComponent(Graphics g){
    			System.out.println("Dans paint componenent");
     
    			//Colonnes
    			g.drawLine(this.getWidth()/15,0,this.getWidth()/15,this.getHeight());
    			g.drawLine(this.getWidth()/15*2,0,this.getWidth()/15*2,this.getHeight());
    			g.drawLine(this.getWidth()/15*3,0,this.getWidth()/15*3,this.getHeight());
    			g.drawLine(this.getWidth()/15*4,0,this.getWidth()/15*4,this.getHeight());
    			g.drawLine(this.getWidth()/15*5,0,this.getWidth()/15*5,this.getHeight());
    			g.drawLine(this.getWidth()/15*6,0,this.getWidth()/15*6,this.getHeight());
    			g.drawLine(this.getWidth()/15*7,0,this.getWidth()/15*7,this.getHeight());
    			g.drawLine(this.getWidth()/15*8,0,this.getWidth()/15*8,this.getHeight());
    			g.drawLine(this.getWidth()/15*9,0,this.getWidth()/15*9,this.getHeight());
    			g.drawLine(this.getWidth()/15*10,0,this.getWidth()/15*10,this.getHeight());
    			g.drawLine(this.getWidth()/15*11,0,this.getWidth()/15*11,this.getHeight());
    			g.drawLine(this.getWidth()/15*12,0,this.getWidth()/15*12,this.getHeight());
    			g.drawLine(this.getWidth()/15*13,0,this.getWidth()/15*13,this.getHeight());
     
    			//Lignes
    			g.drawLine(0, this.getHeight()/15, this.getWidth(), this.getHeight()/15);
    			g.drawLine(0, this.getHeight()/15*2, this.getWidth(), this.getHeight()/15*2);
    			g.drawLine(0, this.getHeight()/15*3, this.getWidth(), this.getHeight()/15*3);
    			g.drawLine(0, this.getHeight()/15*4, this.getWidth(), this.getHeight()/15*4);
    			g.drawLine(0, this.getHeight()/15*5, this.getWidth(), this.getHeight()/15*5);
    			g.drawLine(0, this.getHeight()/15*6, this.getWidth(), this.getHeight()/15*6);
    			g.drawLine(0, this.getHeight()/15*7, this.getWidth(), this.getHeight()/15*7);
    			g.drawLine(0, this.getHeight()/15*8, this.getWidth(), this.getHeight()/15*8);
    			g.drawLine(0, this.getHeight()/15*9, this.getWidth(), this.getHeight()/15*9);
    			g.drawLine(0, this.getHeight()/15*10, this.getWidth(), this.getHeight()/15*10);
    			g.drawLine(0, this.getHeight()/15*11, this.getWidth(), this.getHeight()/15*11);
    			g.drawLine(0, this.getHeight()/15*12, this.getWidth(), this.getHeight()/15*12);
    			g.drawLine(0, this.getHeight()/15*13, this.getWidth(), this.getHeight()/15*13);
    			g.drawLine(0, this.getHeight()/15*14, this.getWidth(), this.getHeight()/15*14);
     
    			page1.paint(g); 
     
    		}
     
     
    	}
    ?

Discussions similaires

  1. Utilisation desktop dans JFrame
    Par laetisam dans le forum Général Java
    Réponses: 4
    Dernier message: 03/05/2012, 15h24
  2. Rendre JFrame "invisible" sans utiliser setVisible ou setSize
    Par kattig dans le forum Agents de placement/Fenêtres
    Réponses: 10
    Dernier message: 23/06/2009, 18h26
  3. utilisation de paintComponent
    Par Lidden dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 09/02/2008, 17h01
  4. JFrame : taille réellement utilisable
    Par Lady dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 23/04/2007, 14h18
  5. [debutant] dimensionnement d'une JFrame avec utilisation d'un pack()
    Par scarpat dans le forum Agents de placement/Fenêtres
    Réponses: 9
    Dernier message: 02/06/2006, 09h45

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