14 Avril
This commit is contained in:
parent
e421bfd319
commit
bfcbd64735
BIN
DEV2.1/TP7:Evenements/Attente.class
Normal file
BIN
DEV2.1/TP7:Evenements/Attente.class
Normal file
Binary file not shown.
61
DEV2.1/TP7:Evenements/Attente.java
Normal file
61
DEV2.1/TP7:Evenements/Attente.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class Attente extends JPanel implements WindowListener{
|
||||||
|
|
||||||
|
boolean plan = false;
|
||||||
|
|
||||||
|
public Attente() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void paintComponent(Graphics pinceau) {
|
||||||
|
// obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard
|
||||||
|
Graphics pinceau2 = pinceau.create();
|
||||||
|
if (this.isOpaque()) {
|
||||||
|
// obligatoire : on repeint toute la surface avec la couleur de fond
|
||||||
|
pinceau2.setColor(Color.GREEN);
|
||||||
|
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
} if (this.plan==true){
|
||||||
|
pinceau2.setColor(Color.GREEN);
|
||||||
|
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
pinceau2.setColor(Color.MAGENTA);
|
||||||
|
pinceau2.fillOval(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
} else{
|
||||||
|
pinceau2.setColor(Color.GREEN);
|
||||||
|
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
pinceau2.setColor(Color.MAGENTA);
|
||||||
|
int[] x={0,this.getWidth()/2,this.getWidth(),this.getWidth()/2};
|
||||||
|
int[] y={this.getHeight()/2,0,this.getHeight()/2,this.getHeight()};
|
||||||
|
pinceau2.drawPolygon(x,y,x.length);
|
||||||
|
pinceau2.fillPolygon(x,y,x.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowDeactivated(WindowEvent evenement){
|
||||||
|
this.plan=false;
|
||||||
|
this.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowActivated(WindowEvent evenement){
|
||||||
|
this.plan=true;
|
||||||
|
this.repaint();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowClosed(WindowEvent evenement){
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowClosing(WindowEvent evenement){
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowDeiconified(WindowEvent evenement){
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowIconified(WindowEvent evenement){
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowOpened(WindowEvent evenement){
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP7:Evenements/Fond.class
Normal file
BIN
DEV2.1/TP7:Evenements/Fond.class
Normal file
Binary file not shown.
36
DEV2.1/TP7:Evenements/Fond.java
Normal file
36
DEV2.1/TP7:Evenements/Fond.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class Fond extends JPanel implements ActionListener{
|
||||||
|
|
||||||
|
public Fond() {
|
||||||
|
super();
|
||||||
|
JButton magenta = new JButton("magenta");
|
||||||
|
JButton cyan = new JButton("cyan");
|
||||||
|
JButton jaune = new JButton("jaune");
|
||||||
|
this.add(magenta);
|
||||||
|
this.add(cyan);
|
||||||
|
this.add(jaune);
|
||||||
|
magenta.addActionListener(this);
|
||||||
|
cyan.addActionListener(this);
|
||||||
|
jaune.addActionListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent evenement){
|
||||||
|
String commande = new String();
|
||||||
|
commande="cyan";
|
||||||
|
if(true==commande.equals(evenement.getActionCommand())){
|
||||||
|
this.setBackground(Color.CYAN);
|
||||||
|
}
|
||||||
|
commande="magenta";
|
||||||
|
if(true==commande.equals(evenement.getActionCommand())){
|
||||||
|
this.setBackground(Color.MAGENTA);
|
||||||
|
}
|
||||||
|
commande="jaune";
|
||||||
|
if(true==commande.equals(evenement.getActionCommand())){
|
||||||
|
this.setBackground(Color.YELLOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP7:Evenements/Mainattente.class
Normal file
BIN
DEV2.1/TP7:Evenements/Mainattente.class
Normal file
Binary file not shown.
17
DEV2.1/TP7:Evenements/Mainattente.java
Normal file
17
DEV2.1/TP7:Evenements/Mainattente.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Mainattente{
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
JFrame fenetre = new JFrame();
|
||||||
|
Attente pan = new Attente();
|
||||||
|
fenetre.setSize(500, 500);
|
||||||
|
fenetre.setLocation(0, 0);
|
||||||
|
fenetre.addWindowListener(pan);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
fenetre.setContentPane(pan);
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP7:Evenements/Mainfond.class
Normal file
BIN
DEV2.1/TP7:Evenements/Mainfond.class
Normal file
Binary file not shown.
16
DEV2.1/TP7:Evenements/Mainfond.java
Normal file
16
DEV2.1/TP7:Evenements/Mainfond.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Mainfond{
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
JFrame fenetre = new JFrame();
|
||||||
|
Fond pan = new Fond();
|
||||||
|
fenetre.setSize(500, 500);
|
||||||
|
fenetre.setLocation(0, 0);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
fenetre.setContentPane(pan);
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user