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 :

formatage de mon frame


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Inscrit en
    Septembre 2009
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 7
    Par défaut formatage de mon frame
    brs a tous, je monte une application qui va faire le dessin d'un cerle d'un carré et d'une line accordé aux dimensions de l'utilisateur j'ai deja monté mon frame mais le formatage est trés bizar j'ai besoin d'aide pour mieux comprendre et mieux formater mon frame voici mon code. merçi d'avance
    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
     
    import java.lang.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Dessin extends Frame implements ItemListener, MouseListener
     {
     
           Label textChoise;
        Label textRadius; 
        Label textSize;
        Label textLength;
        Button b;
        Choice ch;
        TextField t;
        public Dessin()
        {
            textChoise = new Label("Choice what you want to draw",Label.LEFT);
            textRadius =new Label("Please enter the radius",Label.LEFT);
            textSize =new Label("Please enter the side",Label.LEFT);
            textLength =new Label("Please enter the Length",Label.LEFT);
            b =  new Button("Draw");
            add(textChoise);
            ch=new Choice();
            String s[]={"Make your Choise","circle","line","square"};
            for(int i=0;i<s.length;i++)
            ch.add(s[i]);
            add(ch);
     
            setLayout(new GridLayout(4,2));
            setBackground(Color.pink);
            addWindowListener(new w());
     
             t = new TextField(10);
             add(textRadius).setVisible(false);
             add(textSize).setVisible(false);
             add(textLength).setVisible(false);
     
             add(t).setVisible(false);
             add(b).setVisible(false);
             ch.addItemListener(this);
             b.addMouseListener(this);
        }
     
       public class w extends WindowAdapter
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        }
     
        public static void main(String[] args) 
        {
     
            Dessin ff = new Dessin();
            ff.setSize(1000,500);
            ff.setVisible(true);
     
        }
     
     
        public void itemStateChanged(ItemEvent f) 
        {
            String st;
            if(f.getSource()==ch) //Font Style
            {
                st =ch.getSelectedItem();
                if(st.equals("circle"))
                {
                  this.add(textSize).setVisible(false);
                  this.add(textLength).setVisible(false);
     
                  this.add(textRadius).setVisible(true);
                  this.add(t).setVisible(true);
                  this.add(b).setVisible(true);
                }
                else if(st.equals("square"))
                {
                  this.add(textRadius).setVisible(false);
                  this.add(textLength).setVisible(false);
                  this.add(textSize).setVisible(true);
                  this.add(t).setVisible(true);
                  this.add(b).setVisible(true);
                }
                else if(st.equals("line"))
                {
                  this.add(textRadius).setVisible(false);
                  this.add(textSize).setVisible(false);
     
                  this.add(textLength).setVisible(true);
                  this.add(t).setVisible(true);
                  this.add(b).setVisible(true);
                }
            }
     
        }
     
     
        public void mouseClicked(MouseEvent e) 
        {
            System.out.println("azerty");
     
        }
     
     
        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub
     
        }
     
     
        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub
     
        }
     
     
        @Override
        public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub
     
        }
     
     
        @Override
        public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub
     
        }
    }

  2. #2
    Membre actif Avatar de arafat877
    Inscrit en
    Septembre 2010
    Messages
    46
    Détails du profil
    Informations forums :
    Inscription : Septembre 2010
    Messages : 46
    Par défaut Solution
    Salut !
    Tu devera utiliser les Layout, et ton code doit ressembler à quelque chose comme ça :

    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
     
    import java.awt.Button;
    import java.awt.Choice;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.TextField;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
    /**
     *
     * @author Arafat Bouchafra
     * @Date   4 déc. 2010
     * @Time   09:05:07
     */
    public class Dessin extends JPanel {
        JLabel lChoice, lRadius, lSize, lLength;
        JTextField tRadius, tSize, tLength;
        Button b;
        Choice ch;
        TextField t;
     
        public Dessin() {
            super(new GridBagLayout());
     
            lChoice = new JLabel("Choice what you want to draw", JLabel.LEFT);
            lRadius = new JLabel("Please enter the radius", JLabel.LEFT);
            lSize   = new JLabel("Please enter the side", JLabel.LEFT);
            lLength = new JLabel("Please enter the Length", JLabel.LEFT);
     
            tRadius = new JTextField(15);
            tSize   = new JTextField(15);
            tLength = new JTextField(15);
     
            ch = new Choice();
            String s[] = {"Make your Choise", "circle", "line", "square"};
            for (int i = 0; i < s.length; i++) {
                ch.add(s[i]);
            }
            add(ch);
     
            GridBagConstraints c = new GridBagConstraints();
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 0;
            add(lChoice, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 1;
            c.gridy = 0;
            add(ch, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 1;
            add(lRadius, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 1;
            c.gridy = 1;
            add(tRadius, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 2;
            add(lSize, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 1;
            c.gridy = 2;
            add(tSize, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 3;
            add(lLength, c);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 1;
            c.gridy = 3;
            add(tLength, c);
        }
     
        public static void main(String... args) {
            JFrame f = new JFrame("Dessin");
            f.setContentPane(new Dessin());
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(500, 500);
            f.setLocationRelativeTo(null); // pour centrer la frame
            f.setVisible(true);
        }
    }
    Bon courage

Discussions similaires

  1. Formatage de mon pc
    Par juleshervey dans le forum Ordinateurs
    Réponses: 1
    Dernier message: 05/01/2012, 11h12
  2. mon frame clignote
    Par galadorn dans le forum Débuter
    Réponses: 5
    Dernier message: 16/05/2009, 02h05
  3. Pourquoi mon frame ne fonctionne pas sur Safari 3.0.4?
    Par joecool2005 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 05/02/2008, 17h36
  4. Changement du couleur de fond de mon Frame
    Par Siempre Adelante-> dans le forum wxWidgets
    Réponses: 0
    Dernier message: 06/01/2008, 14h41
  5. [XSLT]Formatage de mon html non désiré
    Par Thanos76 dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 25/06/2005, 12h16

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