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
| import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CPremierTPE extends JFrame {
JTextField texte3,texte4,texte5,texte6;
JLabel textefin;
public static void main(String[] args) {
CPremierTPE choix = new CPremierTPE("TPE avion");
choix.pack();
choix.setSize(800,150);
choix.setVisible(true);
}
class CActionCalculer implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
int portance = Integer.parseInt(texte5.getText());
textefin.setText(String.valueOf(portance));
} catch (NumberFormatException ex) {
System.out.println("Le nombre entrée n'est pas valide !");
textefin.setText("salut");
}
}
}
// Le constructeur
CPremierTPE(String titre) {
super(titre);
//*******************************************
// Forcer le thème natif
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception ex) {
System.err.println("Erreur de Look&Feel\n");
}
setLayout(new GridLayout(4,1));
JPanel cellule1 = new JPanel();
JPanel cellule2 = new JPanel();
JLabel texte1 = new JLabel("Ce prgramme détermine le mouvement futur de l'avion, en fonction des paramètres entrés. ");
texte1.setFont(new Font("Monospaced", Font.PLAIN,12));
cellule1.add(texte1);
JLabel texte2 = new JLabel("Entrez dans les cases des forces, les différentes intensités, en Newton, après avoir effacé leur nom.");
texte2.setFont(new Font("Monospaced", Font.PLAIN,12));
cellule2.add(texte2);
add(cellule1);
add(cellule2);
JPanel champs = new JPanel();
champs.setLayout(new GridLayout(1,4));
texte3 = new JTextField(10);
texte3.setText("Poussée");
champs.add(texte3);
texte4 = new JTextField(10);
texte4.setText("Traînée");
champs.add(texte4);
texte5 = new JTextField(10);
texte5.setText("Portance");
champs.add(texte5);
texte6 = new JTextField(10);
texte6.setText("Poids");
champs.add(texte6);
add(champs);
JPanel resultat = new JPanel();
resultat.setLayout(new GridLayout(1,2));
JButton calculer = new JButton("Calculer");
resultat.add(calculer);
textefin = new JLabel(texte5.getText());
textefin.setFont(new Font("Monospaced", Font.PLAIN,12));
resultat.add(textefin);
add(resultat);
calculer.addActionListener(new CActionCalculer());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
} |
Partager