Addition ne fonctionne pas
Je ne comprend pas pourquoi j'arrive pas affecter le champ resultat (Addition des deux champs A + B)
http://www.latrach.net/images/java_addition.JPG
Code:
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
| import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CreatingAWindow extends JFrame{
public static void main(String[] args)
{
new CreatingAWindow(); // Display the window
}
public CreatingAWindow ()
{
JFrame frame = new JFrame("Mon Premier Interface Graphique Java");
int windowWidth = 200;
int windowHeight = 100;
frame.setBounds(0, 0,windowWidth, windowHeight);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JButton monBtn = new JButton("Addition !");
JTextField inputA = new JTextField("");
JTextField inputB = new JTextField("");
JTextField resultat = new JTextField("resultat:");
frame.setLayout(new GridLayout(3, 2));
frame.add(new JLabel("A:"));
frame.add(inputA);
frame.add(new JLabel("B:"));
frame.add(inputB);
frame.add(monBtn);
frame.add(resultat);
monBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
TxtAffectaion() ;
}
});
}
public void TxtAffectaion ()
{
resultat.setText((int) inputA.setText("5")+(int) inputB.setText("1"));
}
} |