#create a button that create new object from the class Vehicle

1 messages · Page 1 of 1 (latest)

pulsar furnaceBOT
#

<@&987246399047479336> please have a look, thanks.

shell horizon
#

Please use the following to format your code, and what's your question?

pulsar furnaceBOT
#

Please use this format for posting code:

```java
// Example java program
int value = 5;
System.out.println(value);
```

Which results in:

// Example java program
int value = 5;
System.out.println(value);

For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.

shell horizon
#

Also not that many people here know French.

vestal sail
#

i want when i click on the button a new object is created from the class vehicle
and have for exmaple objects: vehicule 1, vehicule2 , etc

#
private void boutonActionPerformed(java.awt.event.ActionEvent evt) {    
        System.out.println("Bouton cliqué !");
        
         // Récupérer les informations depuis les champs de texte
        String matricule = matriculeA.getText().trim();
        String marque = MarqueA.getText().trim();
        String model = ModelA.getText().trim();
        String heureEntree = HeureA.getText().trim();
        String electrique = jComboBox2.getSelectedItem().equals("true") ? "true" : "false";
        
        if (matricule.isEmpty() || marque.isEmpty() || model.isEmpty() || heureEntree.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Veuillez remplir tous les champs.");
            return;
        }

        // Créer un nouvel objet Vehicule avec un ID unique
        int vehiculeId = compteurVehicules;
        boolean isElectric = electrique.equals("true");

        Vehicule vehicule = new Vehicule(
            vehiculeId,
            matricule,
            marque,
            model,
            heureEntree,
            isElectric
        );
pulsar furnaceBOT