fin
This commit is contained in:
BIN
DEV2.1/Evenement/Attente$1.class
Normal file
BIN
DEV2.1/Evenement/Attente$1.class
Normal file
Binary file not shown.
BIN
DEV2.1/Evenement/Attente$2.class
Normal file
BIN
DEV2.1/Evenement/Attente$2.class
Normal file
Binary file not shown.
BIN
DEV2.1/Evenement/Attente.class
Normal file
BIN
DEV2.1/Evenement/Attente.class
Normal file
Binary file not shown.
69
DEV2.1/Evenement/Attente.java
Normal file
69
DEV2.1/Evenement/Attente.java
Normal file
@@ -0,0 +1,69 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Attente extends JFrame {
|
||||
private JPanel panel;
|
||||
private boolean isInBackground = false;
|
||||
|
||||
public Attente() {
|
||||
setTitle("Attente");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(300, 300);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// Création du panneau
|
||||
panel = new JPanel() {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (isInBackground) {
|
||||
// Dessiner des triangles lorsque la fenêtre est en arrière-plan
|
||||
dessinerTriangles(g);
|
||||
} else {
|
||||
// Dessiner un disque magenta lorsque la fenêtre est en premier plan
|
||||
g.setColor(Color.MAGENTA);
|
||||
int diametre = Math.min(getWidth(), getHeight()) - 50;
|
||||
int x = (getWidth() - diametre) / 2;
|
||||
int y = (getHeight() - diametre) / 2;
|
||||
g.fillOval(x, y, diametre, diametre);
|
||||
}
|
||||
}
|
||||
};
|
||||
panel.setBackground(Color.GREEN); // Définir la couleur de fond du panneau
|
||||
|
||||
// Ajouter le panneau à la fenêtre
|
||||
add(panel);
|
||||
|
||||
// Ajouter un WindowListener pour détecter les événements de la fenêtre
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowActivated(WindowEvent e) {
|
||||
isInBackground = false;
|
||||
panel.repaint(); // Redessiner le panneau lorsque la fenêtre revient au premier plan
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
isInBackground = true;
|
||||
panel.repaint(); // Redessiner le panneau lorsque la fenêtre passe en arrière-plan
|
||||
}
|
||||
});
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
// Méthode pour dessiner des triangles
|
||||
private void dessinerTriangles(Graphics g) {
|
||||
g.setColor(Color.BLACK);
|
||||
int[] x = null;
|
||||
x = new int[] {90,0,0,90};
|
||||
int[] y = null;
|
||||
y = new int[] {100,0,100,0};
|
||||
g.fillPolygon(x,y,4);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Attente();
|
||||
}
|
||||
}
|
||||
BIN
DEV2.1/Evenement/Fond.class
Normal file
BIN
DEV2.1/Evenement/Fond.class
Normal file
Binary file not shown.
59
DEV2.1/Evenement/Fond.java
Normal file
59
DEV2.1/Evenement/Fond.java
Normal file
@@ -0,0 +1,59 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
class Mypanel extends JPanel implements ActionListener {
|
||||
|
||||
public Mypanel(){
|
||||
super();
|
||||
// Création des boutons
|
||||
JButton cyanButton = new JButton("Cyan");
|
||||
JButton magentaButton = new JButton("Magenta");
|
||||
JButton yellowButton = new JButton("Jaune");
|
||||
|
||||
// Ajout des action listeners aux boutons
|
||||
cyanButton.addActionListener(this);
|
||||
magentaButton.addActionListener(this);
|
||||
yellowButton.addActionListener(this);
|
||||
|
||||
// Création du panneau pour contrôler la couleur de fond
|
||||
this.add(cyanButton);
|
||||
this.add(magentaButton);
|
||||
this.add(yellowButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
switch (command) {
|
||||
case "Cyan":
|
||||
this.setBackground(Color.CYAN);
|
||||
break;
|
||||
case "Magenta":
|
||||
this.setBackground(Color.MAGENTA);
|
||||
break;
|
||||
case "Jaune":
|
||||
this.setBackground(Color.YELLOW);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class Fond{
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 500);
|
||||
fenetre.setTitle("Changement de Fond");
|
||||
fenetre.setLayout(new GridLayout(1, 1));
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// Création du panneau pour contrôler la couleur de fond
|
||||
JPanel panneau = new Mypanel();
|
||||
|
||||
fenetre.add(panneau);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
DEV2.1/Evenement/Mypanel.class
Normal file
BIN
DEV2.1/Evenement/Mypanel.class
Normal file
Binary file not shown.
BIN
DEV2.1/Evenement/Radio.class
Normal file
BIN
DEV2.1/Evenement/Radio.class
Normal file
Binary file not shown.
64
DEV2.1/Evenement/Radio.java
Normal file
64
DEV2.1/Evenement/Radio.java
Normal file
@@ -0,0 +1,64 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Radio extends JFrame implements ActionListener {
|
||||
private JPanel panel;
|
||||
private JRadioButton cyanButton, magentaButton, yellowButton;
|
||||
|
||||
public Radio() {
|
||||
setTitle("Radio");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(300, 200);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// Création du panneau
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout());
|
||||
|
||||
// Création des boutons radio
|
||||
cyanButton = new JRadioButton("Cyan");
|
||||
magentaButton = new JRadioButton("Magenta");
|
||||
yellowButton = new JRadioButton("Yellow");
|
||||
|
||||
// Ajout des boutons radio au panneau
|
||||
panel.add(cyanButton);
|
||||
panel.add(magentaButton);
|
||||
panel.add(yellowButton);
|
||||
|
||||
// Ajout des boutons radio à un groupe de boutons pour permettre la sélection unique
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
buttonGroup.add(cyanButton);
|
||||
buttonGroup.add(magentaButton);
|
||||
buttonGroup.add(yellowButton);
|
||||
|
||||
// Ajout d'un écouteur d'événements aux boutons radio
|
||||
cyanButton.addActionListener(this);
|
||||
magentaButton.addActionListener(this);
|
||||
yellowButton.addActionListener(this);
|
||||
|
||||
// Ajout du panneau à la fenêtre
|
||||
add(panel);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Color color = null;
|
||||
// Vérifier quel bouton radio est sélectionné et définir la couleur correspondante
|
||||
if (e.getSource() == cyanButton) {
|
||||
color = Color.CYAN;
|
||||
} else if (e.getSource() == magentaButton) {
|
||||
color = Color.MAGENTA;
|
||||
} else if (e.getSource() == yellowButton) {
|
||||
color = Color.YELLOW;
|
||||
}
|
||||
// Définir la couleur de fond du panneau
|
||||
panel.setBackground(color);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Radio();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user