bonjour à tous!!
j'ai un petit soucis.
je creé un rectangle et j'aimerai par clic sur un bouton (nommé "jaune" ou "vert") que le rectangle change de couleur
j'ai déjà ça, mais ça ne modifie pas la couleur du rectangle..
[code]
import
java.awt.*;import
javax.swing.*;import
java.awt.event.ActionEvent;import
java.awt.event.ActionListener;
public
class Paint extends Frame implements ActionListener//extends component
{
BorderLayout
fl;GridLayout
grid;Color
col;Frame
f;Button
vert,jaune;public Paint(){
fl = new BorderLayout();setLayout(
fl);grid = new GridLayout(5,1);setLayout(
grid);jaune = new Button("jaune");vert = new Button("vert");add(
"South",vert);add(
"South",jaune);jaune.addActionListener(this);vert.addActionListener(this);setBackground(Color.
white);setTitle(
"Essai");setSize(300,200);
setVisible(
true);}
publicvoid paint(Graphics g){
g.fillRect(10,10,140,140);
g.setColor(
col);}
publicvoid actionPerformed(ActionEvent e){
if (e.getSource() == jaune){
col = Color.yellow;repaint();
}
}
publicstaticvoid main(String[] args) {
Paint jc =
new Paint();}
}
[/code]
donc si quelqu'un pourrait m'aider, je l'en remercie d'avance