This commit is contained in:
Simoes Lukas
2025-03-11 10:02:42 +01:00
parent 9441c8978a
commit 2a0aa37baa
47 changed files with 561 additions and 3 deletions

BIN
DEV2.1/TP08/Attente.class Normal file

Binary file not shown.

35
DEV2.1/TP08/Attente.java Normal file
View File

@@ -0,0 +1,35 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Attente {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(300,200);
fenetre.setLocation(100,100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLayout(new GridLayout(1, 1));
JPanel panneau = new JPanel();
panneau.setLayout(new BorderLayout());
panneau.setBackground(Color.GREEN);
FenetreListener listener = new FenetreListener();
fenetre.addWindowListener(listener);
fenetre.add(panneau);
if (listener.getEstActive()) {
System.out.println("Fenetre activée");
panneau.add(new CercleMagenta());
fenetre.repaint();
}
else {
System.out.println("Fenetre désactivée");
panneau.add(new Sautoir());
fenetre.repaint();
}
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@@ -0,0 +1,19 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class CercleMagenta extends JComponent {
@Override
public void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()) {
secondPinceau.setColor(this.getBackground());
secondPinceau.drawRect(0, 0, this.getWidth(), this.getHeight());
}
secondPinceau.setColor(Color.MAGENTA);
secondPinceau.fillOval(0, 0, this.getWidth(), this.getHeight());
}
}

Binary file not shown.

View File

@@ -0,0 +1,28 @@
import java.awt.event.*;
import javax.swing.*;
public class FenetreListener extends WindowAdapter {
private boolean estActive;
public FenetreListener() {
this.estActive = true;
}
public boolean getEstActive() {
return this.estActive;
}
@Override
public void windowActivated(WindowEvent e) {
this.estActive = true;
}
@Override
public void windowDeactivated(WindowEvent e) {
this.estActive = false;
}
}

BIN
DEV2.1/TP08/Fond$1.class Normal file

Binary file not shown.

BIN
DEV2.1/TP08/Fond$2.class Normal file

Binary file not shown.

BIN
DEV2.1/TP08/Fond$3.class Normal file

Binary file not shown.

BIN
DEV2.1/TP08/Fond.class Normal file

Binary file not shown.

45
DEV2.1/TP08/Fond.java Normal file
View File

@@ -0,0 +1,45 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Fond {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(300,200);
fenetre.setLocation(100,100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLayout(new GridLayout(1, 1));
JPanel panneau = new JPanel();
JButton bouton1 = new JButton("Cyan");
JButton bouton2 = new JButton("Magenta");
JButton bouton3 = new JButton("Jaune");
bouton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(Color.CYAN);
}
});
bouton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(Color.MAGENTA);
}
});
bouton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evenement) {
panneau.setBackground(Color.YELLOW);
}
});
panneau.add(bouton1);
panneau.add(bouton2);
panneau.add(bouton3);
fenetre.add(panneau);
fenetre.setVisible(true);
}
}

BIN
DEV2.1/TP08/Sautoir.class Normal file

Binary file not shown.

38
DEV2.1/TP08/Sautoir.java Normal file
View File

@@ -0,0 +1,38 @@
import java.awt.*;
import javax.swing.*;
public class Sautoir extends JComponent {
@Override
protected void paintComponent(Graphics pinceau) {
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
Graphics secondPinceau = pinceau.create();
// obligatoire : si le composant n'est pas censé être transparent
if (this.isOpaque()) {
// obligatoire : on repeint toute la surface avec la couleur de fond
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
int[] coord_x = {0, this.getWidth(), 0, this.getWidth()};
int[] coord_y = {0, 0, this.getHeight(), this.getHeight()};
Polygon p = new Polygon(coord_x, coord_y, 4);
secondPinceau.setColor(Color.CYAN);
secondPinceau.fillPolygon(p);
}
public static void main(String[] args) {
JFrame fenetre = new JFrame();
GridLayout layout = new GridLayout(5, 5);
// on configure la fenetre
fenetre.setSize(250, 250);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLayout(layout);
for (int i = 0; i != 25; i++) {
fenetre.add(new Sautoir());
}
fenetre.setVisible(true);
}
}