This commit is contained in:
Emmanuel Srivastava
2025-03-05 20:44:11 +01:00
parent 1384bb65e9
commit 79cf818d89
2 changed files with 42 additions and 55 deletions

View File

@@ -1,11 +1,12 @@
import java.awt.*;
import javax.swing.*;
public class Fond {
public class Fond extends JPanel implements ActionListener {
private JButton Cyan, Magenta, Jaune;
public Fond() {
this.setLayout(null);
this.Cyan = new JButton("Cyan");
this.Magenta = new JButton("Magenta");
this.Jaune = new JButton("Jaune");
@@ -18,19 +19,19 @@ public class Fond {
this.Magenta.addActionListener(this);
this.Jaune.addActionListener(this);
frame.add(this.Cyan);
frame.add(this.Magenta);
frame.add(this.Jaune);
this.add(this.Cyan);
this.add(this.Magenta);
this.add(this.Jaune);
}
@Override
public void actionPerformed(ActionEvent evenement) {
if (evenement.getSource() == this.Cyan) {
frame.setBackground(Color.CYAN);
this.setBackground(Color.CYAN);
} else if (evenement.getSource() == this.Magenta) {
frame.setBackground(Color.MAGENTA);
this.setBackground(Color.MAGENTA);
} else if (evenement.getSource() == this.Jaune) {
frame.setBackground(Color.JAUNE);
this.setBackground(Color.YELLOW);
}
}
}

View File

@@ -9,32 +9,23 @@ public class MainFond {
Fond panel = new Fond();
frame.add(panel, BorderLayout.CENTER);
frame.add(panel);
frame.setSize(500,500);
frame.setLocation(500,250);
frame.setVisible(true);
}
}
[srivasta@vm-srivasta 1.Fond]$ javac MainFond.java
./Fond.java:4: error: cannot find symbol
public class Fond extends JPanel implements ActionListener {
^
symbol: class ActionListener
./Fond.java:27: error: cannot find symbol
public void actionPerformed(ActionEvent evenement) {
^
symbol: class ActionEvent
location: class Fond
MainFond.java:12: error: no suitable method found for add(Fond,String)
frame.add(panel, BorderLayout.CENTER);
^
method Container.add(String,Component) is not applicable
(argument mismatch; Fond cannot be converted to String)
method Container.add(Component,int) is not applicable
(argument mismatch; Fond cannot be converted to Component)
method Container.add(Component,Object) is not applicable
(argument mismatch; Fond cannot be converted to Component)
./Fond.java:8: error: cannot find symbol
this.setLayout(null);
^
symbol: method setLayout(<null>)
./Fond.java:17: error: incompatible types: Fond cannot be converted to ActionListener
this.Cyan.addActionListener(this);
^
@@ -44,43 +35,38 @@ MainFond.java:12: error: no suitable method found for add(Fond,String)
./Fond.java:19: error: incompatible types: Fond cannot be converted to ActionListener
this.Jaune.addActionListener(this);
^
./Fond.java:21: error: cannot find symbol
frame.add(this.Cyan);
^
symbol: variable frame
location: class Fond
./Fond.java:22: error: cannot find symbol
frame.add(this.Magenta);
^
symbol: variable frame
location: class Fond
./Fond.java:23: error: cannot find symbol
frame.add(this.Jaune);
^
symbol: variable frame
location: class Fond
./Fond.java:26: error: method does not override or implement a method from a supertype
@Override
^
./Fond.java:29: error: cannot find symbol
frame.setBackground(Color.CYAN);
^
symbol: variable frame
location: class Fond
./Fond.java:31: error: cannot find symbol
frame.setBackground(Color.MAGENTA);
^
symbol: variable frame
location: class Fond
./Fond.java:33: error: cannot find symbol
frame.setBackground(Color.JAUNE);
^
setBackground(Color.JAUNE);
^
symbol: variable JAUNE
location: class Color
./Fond.java:33: error: cannot find symbol
frame.setBackground(Color.JAUNE);
^
symbol: variable frame
location: class Fond
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
14 errors
7 errors
[srivasta@vm-srivasta 1.Fond]$ q
[srivasta@vm-srivasta 1.Fond]$ javac MainFond.java
./Fond.java:4: error: cannot find symbol
public class Fond extends JPanel implements ActionListener {
^
symbol: class ActionListener
./Fond.java:28: error: cannot find symbol
public void actionPerformed(ActionEvent evenement) {
^
symbol: class ActionEvent
location: class Fond
./Fond.java:18: error: incompatible types: Fond cannot be converted to ActionListener
this.Cyan.addActionListener(this);
^
./Fond.java:19: error: incompatible types: Fond cannot be converted to ActionListener
this.Magenta.addActionListener(this);
^
./Fond.java:20: error: incompatible types: Fond cannot be converted to ActionListener
this.Jaune.addActionListener(this);
^
./Fond.java:27: error: method does not override or implement a method from a supertype
@Override
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
6 errors