This commit is contained in:
Adrian POURCHOT 2023-04-14 11:29:17 +02:00
parent e421bfd319
commit bfcbd64735
8 changed files with 130 additions and 0 deletions

Binary file not shown.

View 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){
}
}

Binary file not shown.

View 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);
}
}
}

Binary file not shown.

View 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);
}
}

Binary file not shown.

View 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);
}
}