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
| public class Fen_cde extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Fen_cde frame = new Fen_cde();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Fen_cde() {
setTitle("Commande");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 631, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new GridLayout(4, 1, 0, 0));
JPanel panel_1 = new JPanel();
contentPane.add(panel_1);
JLabel lblArticle = new JLabel("Article 1 - Prix unitaire = 20 \u20AC : Nombre =");
panel_1.add(lblArticle);
final JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3"}));
panel_1.add(comboBox);
JLabel lblTotal = new JLabel("Total = ");
panel_1.add(lblTotal);
textField = new JTextField();
panel_1.add(textField);
textField.setColumns(10);
JPanel panel_2 = new JPanel();
contentPane.add(panel_2);
JLabel lblNewLabel = new JLabel("Article 2 - Prix unitaire = 30 \u20AC : Nombre =");
panel_2.add(lblNewLabel);
final JComboBox comboBox_1 = new JComboBox();
comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5"}));
panel_2.add(comboBox_1);
JLabel label = new JLabel("Total = ");
panel_2.add(label);
textField_1 = new JTextField();
panel_2.add(textField_1);
textField_1.setColumns(10);
JPanel panel_3 = new JPanel();
contentPane.add(panel_3);
JLabel lblNewLabel_1 = new JLabel("Article 3 - Prix unitaire = 40 \u20AC : Nombre =");
panel_3.add(lblNewLabel_1);
final JComboBox comboBox_2 = new JComboBox();
comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"0", "5", "10", "15", "20", "50"}));
panel_3.add(comboBox_2);
JLabel label_1 = new JLabel("Total = ");
panel_3.add(label_1);
textField_2 = new JTextField();
panel_3.add(textField_2);
textField_2.setColumns(10);
JPanel panel_4 = new JPanel();
contentPane.add(panel_4);
JButton btnCalculDuTotal = new JButton("Calcul du total");
btnCalculDuTotal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int num1 = Integer.parseInt((String)comboBox.getSelectedItem());
int val1 = 20 * num1;
textField.setText(Integer.toString(val1));
int num2 = Integer.parseInt((String)comboBox_1.getSelectedItem());
int val2 = 30 * num2;
textField_1.setText(Integer.toString(val2));
int num3 = Integer.parseInt((String)comboBox_2.getSelectedItem());
int val3 = 40 * num3;
textField_2.setText(Integer.toString(val3));
String rrr = Integer.toString(val1+val2+val3);
textField_3.setText(rrr);
}
});
panel_4.add(btnCalculDuTotal);
JLabel label_2 = new JLabel("Total = ");
panel_4.add(label_2);
textField_3 = new JTextField();
panel_4.add(textField_3);
textField_3.setColumns(10);
}
} |
Partager