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

AWT/Swing Java Discussion :

Superposition jPanel Cercle


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Avril 2007
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 37
    Par défaut Superposition jPanel Cercle
    Bonjour,

    J'ai vu pas mal de choses sur mon problème, venant généralement de l'utilisation d'AWT avec du SWING dans une même frame.
    Là je pense utiliser que du SWING et mon jLabel reste malgré tout derrière mon cercle alors j'en appelle à votre aide
    Je veux donc que mon jLabel1 se superpose sur mon horloge pour que je puisse afficher les heures tout autour.
    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
    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
    package tp2;
     
    import java.awt.BorderLayout;
    import java.awt.Dimension;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.Font;
    import com.borland.jbcl.layout.XYLayout;
    import com.borland.jbcl.layout.*;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    import javax.swing.JLabel;
    import javax.swing.*;
    import javax.swing.border.TitledBorder;
     
     
    /**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2007</p>
     *
     * <p>Company: </p>
     *
     * @author not attributable
     * @version 1.0
     */
    public class Frame1 extends JFrame {
        JPanel contentPane;
        JPanel jPanel1 = new JPanel();
         Heure heureCourante = new Heure (120);
        XYLayout xYLayout1 = new XYLayout();
        JTextField jTextField1 = new JTextField(heureCourante.toString());
        public Frame1() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
     
        /**
         * Component initialization.
         *
         * @throws java.lang.Exception
         */
        private void jbInit() throws Exception {
            int haut =jPanel1.getHeight(); ;
            int large =jPanel1.getWidth(); ;
     
            contentPane = (JPanel) getContentPane();
            setSize(new Dimension(402, 311));
            setTitle("Frame Title");
            jPanel1.setLayout(xYLayout1);
            jTextField1.addActionListener(new Frame1_jTextField1_actionAdapter(this));
            jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 20));
            jLabel1.setForeground(Color.darkGray);
            jLabel1.setBorder(null);
            jLabel1.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
            jLabel1.setDoubleBuffered(true);
            jLabel1.setDisplayedMnemonic('0');
            jLabel1.setLabelFor(null);
            jLabel1.setLabelFor(contentPane);
            jLabel1.setText("12");
            contentPane.setBackground(SystemColor.control);
            contentPane.setToolTipText("");
            contentPane.setLayout(borderLayout1);
            jPanel1.setActionMap(null);
            contentPane.add(jPanel2, java.awt.BorderLayout.CENTER);
            jPanel2.add(jLabel1);
            contentPane.add(jPanel1, java.awt.BorderLayout.NORTH);
            jPanel1.add(jTextField1, new XYConstraints(18, 0, -1, -1));
            timer.start(); // pour démarrer le décompte du temps
     
        }
     
        private void affichehorloge() {
            Graphics g = jPanel1.getGraphics();
            Graphics h = jPanel1.getGraphics();
            Graphics k = jPanel1.getGraphics();
            h.setColor(Color.black);
            g.setColor(Color.white);
            k.setColor(Color.darkGray);
            int haut = jPanel1.getHeight();
            int large = jPanel1.getWidth();
            int taille = Math.min(large,haut);
            jLabel1.setLocation(large/2,-40);
            h.drawOval((large/2)-(taille/2)-1,(haut/2)-(taille/2)+3,(taille+1),(taille-5));
            g.fillOval((large/2)-(taille/2),(haut/2)-(taille/2)+4,taille,taille-6) ;
            k.fillOval((large/2)-(12/2),(haut/2)-(12/2),12,12);
     
        }
     
        ActionListener action = new ActionListener() {
    public void actionPerformed(ActionEvent event) {
        heureCourante.augmente(1);
        jTextField1.setText(heureCourante.toString());
     
        //c'est la pour affichehorloge()
        affichehorloge();
    }
    };
     
        Timer timer = new Timer(1000, action);// 1000 millisecondes
        JLabel jLabel1 = new JLabel();
        PaneLayout paneLayout1 = new PaneLayout();
        BorderLayout borderLayout1 = new BorderLayout();
        TitledBorder titledBorder1 = new TitledBorder("");
        JPanel jPanel2 = new JPanel();
    }
     
     
    class Frame1_jTextField1_actionAdapter implements ActionListener {
        private Frame1 adaptee;
        Frame1_jTextField1_actionAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        }
     
        public void actionPerformed(ActionEvent e) {
        }
     
     
    }

  2. #2
    Membre averti
    Inscrit en
    Avril 2007
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 37
    Par défaut
    S'il vous plait je ne trouve vraiment pas comment faire pour mettre mon jLabel1 par dessus mes cercles.
    Une petite aide ne serait pas de refus

  3. #3
    Rédacteur
    Avatar de eclesia
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    2 111
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 111
    Par défaut
    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
    private void affichehorloge() {
            Graphics g = jPanel1.getGraphics();
            Graphics h = jPanel1.getGraphics();
            Graphics k = jPanel1.getGraphics();
            h.setColor(Color.black);
            g.setColor(Color.white);
            k.setColor(Color.darkGray);
            int haut = jPanel1.getHeight();
            int large = jPanel1.getWidth();
            int taille = Math.min(large,haut);
            jLabel1.setLocation(large/2,-40);
            h.drawOval((large/2)-(taille/2)-1,(haut/2)-(taille/2)+3,(taille+1),(taille-5));
            g.fillOval((large/2)-(taille/2),(haut/2)-(taille/2)+4,taille,taille-6) ;
            k.fillOval((large/2)-(12/2),(haut/2)-(12/2),12,12);
     
        }
    c'est quoi cette horreur ?!

    fait une vrai classe pour ton horloge, du genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    class Horloge extends JPanel{
     
     
    @Override
    public void paintComponant(Graphics g){
     
        //la je dessine l'horloge
     
        paintChildren(g);
     
    }
     
    }

Discussions similaires

  1. Probleme superposition Jpanel et JFrame
    Par Lulou40 dans le forum Débuter
    Réponses: 4
    Dernier message: 29/10/2009, 12h05
  2. [JPanel] Affichage - superposition
    Par Alphonse87 dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 08/08/2008, 10h11
  3. Superposition Cercle et JButton
    Par notox dans le forum 2D
    Réponses: 1
    Dernier message: 07/05/2008, 15h03
  4. Superposition JPanel dans JTabbedPane
    Par rems033 dans le forum AWT/Swing
    Réponses: 9
    Dernier message: 23/06/2007, 13h13
  5. JPanel, EmptyBorder et Superposition
    Par pigeonus dans le forum AWT/Swing
    Réponses: 7
    Dernier message: 19/04/2007, 15h54

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