diff --git a/DEV.2.1/TP/TP8-Evenements/1.Fond/Fond.java b/DEV.2.1/TP/TP8-Evenements/1.Fond/Fond.java index 620c215..8250dee 100644 --- a/DEV.2.1/TP/TP8-Evenements/1.Fond/Fond.java +++ b/DEV.2.1/TP/TP8-Evenements/1.Fond/Fond.java @@ -5,6 +5,7 @@ public class Fond { 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"); @@ -12,5 +13,24 @@ public class Fond { this.Cyan.setBounds(100,50,100,20); this.Magenta.setBounds(220,50,100,20); this.Jaune.setBounds(320,50,100,20); + + this.Cyan.addActionListener(this); + this.Magenta.addActionListener(this); + this.Jaune.addActionListener(this); + + frame.add(this.Cyan); + frame.add(this.Magenta); + frame.add(this.Jaune); + } + + @Override + public void actionPerformed(ActionEvent evenement) { + if (evenement.getSource() == this.Cyan) { + frame.setBackground(Color.CYAN); + } else if (evenement.getSource() == this.Magenta) { + frame.setBackground(Color.MAGENTA); + } else if (evenement.getSource() == this.Jaune) { + frame.setBackground(Color.JAUNE); + } } } \ No newline at end of file diff --git a/DEV.2.1/TP/TP8-Evenements/1.Fond/MainFond.java b/DEV.2.1/TP/TP8-Evenements/1.Fond/MainFond.java index 864f758..6276079 100644 --- a/DEV.2.1/TP/TP8-Evenements/1.Fond/MainFond.java +++ b/DEV.2.1/TP/TP8-Evenements/1.Fond/MainFond.java @@ -6,13 +6,81 @@ public class MainFond { JFrame frame = new JFrame("Fond"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel panel = new JPanel(); - Fond test = new Fond(); + Fond panel = new Fond(); frame.add(panel, BorderLayout.CENTER); frame.setSize(500,500); frame.setLocation(500,250); frame.setVisible(true); } -} \ No newline at end of file +} + +[srivasta@vm-srivasta 1.Fond]$ javac MainFond.java +./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() +./Fond.java:17: error: incompatible types: Fond cannot be converted to ActionListener + this.Cyan.addActionListener(this); + ^ +./Fond.java:18: error: incompatible types: Fond cannot be converted to ActionListener + this.Magenta.addActionListener(this); + ^ +./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); + ^ + 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