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 :

Action listenet en jframe


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Cyber security
    Inscrit en
    Octobre 2022
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Cyber security

    Informations forums :
    Inscription : Octobre 2022
    Messages : 4
    Par défaut Action listenet en jframe
    Comment entrer des valeurs de côté d'un carre et on l'affiche après calculer son périmètre?
    Quelles sont les composants qui sont nécessaires à ce programme

  2. #2
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 713
    Par défaut
    Bonjour
    Peux-tu nous montrer le code que tu as essayé ?
    Labor improbus omnia vincit un travail acharné vient à bout de tout - Ambroise Paré (1510-1590)

    Consulter sans modération la FAQ ainsi que les bons ouvrages : http://jmdoudoux.developpez.com/cours/developpons/java/

  3. #3
    Membre à l'essai
    Homme Profil pro
    Cyber security
    Inscrit en
    Octobre 2022
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Cyber security

    Informations forums :
    Inscription : Octobre 2022
    Messages : 4
    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
    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
     
    /**
      *
      * Description
      *
      * @version 1.0 from 25/04/2023
      * @author 
      */
     
    public class KAKA extends JFrame {
      // start attributes
      private JLabel jLabel1 = new JLabel();
      private JTextField jTextField1 = new JTextField();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();
      private JLabel jLabel2 = new JLabel();
      private JLabel jLabel3 = new JLabel();
      private JLabel jLabel4 = new JLabel();
      private JTextField jTextField2 = new JTextField();
      private JLabel jLabel5 = new JLabel();
      private JTextField jTextField3 = new JTextField();
      private JCheckBox jCheckBox1 = new JCheckBox();
      private JCheckBox jCheckBox2 = new JCheckBox();
      // end attributes
     
      public KAKA(String title) { 
        // Frame-Init
        super(title);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        int frameWidth = 297; 
        int frameHeight = 404;
        setSize(frameWidth, frameHeight);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (d.width - getSize().width) / 2;
        int y = (d.height - getSize().height) / 2;
        setLocation(x, y);
        setResizable(false);
        Container cp = getContentPane();
        cp.setLayout(null);
        // start components
     
        cp.setBackground(Color.CYAN);
        jLabel1.setBounds(120, 24, 46, 41);
        jLabel1.setText("Coté");
        jLabel1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
        cp.add(jLabel1);
        jTextField1.setBounds(216, 32, 38, 36);
        jTextField1.setHorizontalAlignment(SwingConstants.CENTER);
        cp.add(jTextField1);
        jButton1.setBounds(32, 248, 75, 25);
        jButton1.setText("Périmètre");
        jButton1.setMargin(new Insets(2, 2, 2, 2));
        jButton1.addActionListener(new ActionListener() { 
          public void actionPerformed(ActionEvent evt) { 
            jButton1_ActionPerformed(evt);
          }
        });
        cp.add(jButton1);
        jButton2.setBounds(32, 312, 75, 25);
        jButton2.setText("Surface");
        jButton2.setMargin(new Insets(2, 2, 2, 2));
        jButton2.addActionListener(new ActionListener() { 
          public void actionPerformed(ActionEvent evt) { 
            jButton2_ActionPerformed(evt);
          }
        });
        cp.add(jButton2);
        jLabel2.setBounds(160, 240, 62, 36);
        jLabel2.setText("");
        jLabel2.setBackground(Color.WHITE);
        jLabel2.setOpaque(true);
        jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
        cp.add(jLabel2);
        jLabel3.setBounds(160, 304, 62, 36);
        jLabel3.setText("");
        jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel3.setBackground(Color.WHITE);
        jLabel3.setOpaque(true);
        cp.add(jLabel3);
        jLabel4.setBounds(120, 96, 85, 25);
        jLabel4.setText("Longueur");
        jLabel4.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
        cp.add(jLabel4);
        jTextField2.setBounds(216, 88, 38, 36);
        jTextField2.setHorizontalAlignment(SwingConstants.CENTER);
        cp.add(jTextField2);
        jLabel5.setBounds(120, 160, 78, 25);
        jLabel5.setText("Largeur");
        jLabel5.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
        cp.add(jLabel5);
        jTextField3.setBounds(216, 152, 38, 36);
        jTextField3.setHorizontalAlignment(SwingConstants.CENTER);
        cp.add(jTextField3);
        jCheckBox1.setBounds(16, 40, 76, 20);
        jCheckBox1.setText("Carre");
        jCheckBox1.setOpaque(false);
        jCheckBox1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
        jCheckBox1.addActionListener(new ActionListener() { 
          public void actionPerformed(ActionEvent evt) { 
            jCheckBox1_ActionPerformed(evt);
     
          }
        });
        cp.add(jCheckBox1);
        jCheckBox2.setBounds(16, 128, 108, 28);
        jCheckBox2.setText("Rectangle");
        jCheckBox2.setOpaque(false);
        jCheckBox2.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
        jCheckBox2.addActionListener(new ActionListener() { 
          public void actionPerformed(ActionEvent evt) { 
            jCheckBox2_ActionPerformed(evt);
          }
        });
        cp.add(jCheckBox2);
        // end components
     
        setVisible(true);
      } // end of public KAKA
     
     
     
      public void jButton1_ActionPerformed(ActionEvent evt) {
        //Carre
        int a= Integer.parseInt(jTextField1.getText());
        int c= 4*a;
        String result= String.valueOf(c);
        jLabel2.setText( "  " +result);
        // TODO add your code here
      } // end of jButton1_ActionPerformed
     
      public void jButton2_ActionPerformed(ActionEvent evt) {
        //Carre
        int a= Integer.parseInt(jTextField1.getText());
        int c= a*a;
        String result= String.valueOf(c);
        jLabel3.setText( "  " +result);
        // TODO add your code here
      } // end of jButton2_ActionPerformed
     
      // TODO add your code here
      public void jCheckBox1_ActionPerformed(ActionEvent evt) {
        jCheckBox1=(JCheckBox)event.getsource();
        if(jCheckBox1.isSelected()){
          jCheckBox1.setSelected(true);
          jLabel1.setBounds(120, 24, 46, 41);
          jLabel1.setText("Coté");
          jLabel1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
          cp.add(jLabel1);
          jTextField1.setBounds(216, 32, 38, 36);
          jTextField1.setHorizontalAlignment(SwingConstants.CENTER);
          cp.add(jTextField1);
        }
        // TODO add your code here
      } // end of jCheckBox1_ActionPerformed
     
      public void jCheckBox2_ActionPerformed(ActionEvent evt) {
        jCheckBox1=(JCheckBox) event.getsource();
        if(jCheckBox1.isSelected()){
          jCheckBox1.setSelected(true);
     
        }
     
        // TODO add your code here
      } // end of jCheckBox2_ActionPerformed
     
      // end methods
     
      public static void main(String[] args) {
        new KAKA("KAKA");
      } // end of main
     
    } // end of class KAKA

  4. #4
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 713
    Par défaut
    Bon, déjà, cela ne marche pas car :
    event n'existe pas. il faut le remplacer par evt
    cp doit être déclaré dans ce que tu appelles "// start attributes" à savoir les champs de classe pour qu'il soit utilisable dans jCheckBox1_ActionPerformed
    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
      // TODO add your code here
      public void jCheckBox1_ActionPerformed(ActionEvent evt) {
        jCheckBox1=(JCheckBox)event.getsource();
        if(jCheckBox1.isSelected()){
          jCheckBox1.setSelected(true);
          jLabel1.setBounds(120, 24, 46, 41);
          jLabel1.setText("Coté");
          jLabel1.setFont(new Font("@Malgun Gothic", Font.BOLD, 16));
          cp.add(jLabel1);
          jTextField1.setBounds(216, 32, 38, 36);
          jTextField1.setHorizontalAlignment(SwingConstants.CENTER);
          cp.add(jTextField1);
        }
        // TODO add your code here
      } // end of jCheckBox1_ActionPerformed
     
      public void jCheckBox2_ActionPerformed(ActionEvent evt) {
        jCheckBox1=(JCheckBox) event.getsource();
        if(jCheckBox1.isSelected()){
          jCheckBox1.setSelected(true);
     
        }
     
        // TODO add your code here
      } // end of jCheckBox2_ActionPerformed
    Labor improbus omnia vincit un travail acharné vient à bout de tout - Ambroise Paré (1510-1590)

    Consulter sans modération la FAQ ainsi que les bons ouvrages : http://jmdoudoux.developpez.com/cours/developpons/java/

Discussions similaires

  1. JFrame pour état d'avancement de plusieurs actions
    Par maccormick dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 01/09/2010, 08h48
  2. Mettre une action sur la croix rouge dune JFrame
    Par nzo70 dans le forum Débuter
    Réponses: 2
    Dernier message: 23/12/2008, 18h17
  3. Bloquer action d'une JFrame
    Par Baptiste Wicht dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 23/05/2007, 13h38
  4. [resolulu][SWING] action avant de fermer une JFrame
    Par berg dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 17/06/2006, 23h15
  5. Action à la fermeture d'une JFrame
    Par Heimdal dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 26/04/2006, 18h24

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