Bonjour,
j'ai essayé d'exécuter ce programme java , il m'affiche un bouton ,mais pas d'affichage d'actions .
slv j'ai besoin de votre aide .
voici le programme:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class tp7 implements ActionListener {
JFrame f2 = new JFrame("fenêtre 2");
public static void main(String[] args) {
JFrame f1 = new JFrame("fenêtre 1");
JFrame f2 = new JFrame("fenêtre 2");
JPanel p =new JPanel();
JButton b=new JButton("up");
b.addActionListener(new tp7()); // à l'intérieur du main "new tp7()"
b.setActionCommand("u");
p.add(b);
f1.add(p);
f1.setVisible(true);
f1.setSize(300,300);
f1.setLocation(100,100);
f2.setVisible(true);
f2.setSize(300,300);
f2.setLocation(400,100);
}
void h() { int a=f2.getLocation().x; int b=f2.getLocation().y;
f2.setLocation(a+30,b+50);
}
public void actionPerformed(ActionEvent k) {
String command = k.getActionCommand();
if(command.equals("u")) {h();}
}
}
Configuration: Windows XP Internet Explorer 6.0