Ajout TP09 / TP10

This commit is contained in:
HORVILLE 2022-03-21 17:26:34 +01:00
parent f22fb9811a
commit 879005c862
12 changed files with 5918 additions and 0 deletions

5689
APL2.1/TP09/Dames/Dames.mdj Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,75 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Funny extends JComponent implements WindowListener {
private boolean foreground;
public Funny() {
super();
foreground = true;
}
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) {}
public void windowActivated(WindowEvent evt) {
foreground = true;
repaint();
}
public void windowDeactivated(WindowEvent evt) {
foreground = false;
repaint();
}
@Override
protected void paintComponent(Graphics brush) {
Graphics newBrush = brush.create();
if (this.isOpaque()) {
newBrush.setColor(this.getBackground());
newBrush.fillRect(0, 0, this.getWidth(), this.getHeight());
}
newBrush.setColor(Color.GREEN);
newBrush.fillRect(0, 0, getWidth(), getHeight());
if (foreground) {
newBrush.setColor(Color.MAGENTA);
newBrush.fillOval(0, 0, getWidth(), getHeight());
} else {
newBrush.setColor(Color.CYAN);
int[] x1 = {0, getWidth(), getWidth() / 2};
int[] y1 = {0, 0, getHeight() / 2};
int[] x2 = {0, getWidth(), getWidth() / 2};
int[] y2 = {getHeight(), getHeight(), getHeight() / 2};
newBrush.fillPolygon(x1, y1, 3);
newBrush.fillPolygon(x2, y2, 3);
}
}
}
public class Attente {
public static void main(String[] args) {
JFrame f = new JFrame("Attente");
f.setSize(200, 200);
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(null);
Funny n = new Funny();
n.setSize(f.getWidth(), f.getHeight());
n.setLocation(0, 0);
f.add(n);
f.addWindowListener(n);
f.setVisible(true);
}
}

Binary file not shown.

View File

@ -0,0 +1,50 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Observer implements ActionListener {
public Observer() {
}
public void actionPerformed(ActionEvent evt) {
String name = evt.getActionCommand();
JRadioButton rb = (JRadioButton)evt.getSource();
JPanel f = (JPanel)rb.getParent();
if (name == "Jaune") {
f.setBackground(Color.YELLOW);
} else if (name == "Cyan") {
f.setBackground(Color.CYAN);
} else if (name == "Magenta") {
f.setBackground(Color.MAGENTA);
}
}
}
public class Combinaison {
public static void main(String[] args) {
JFrame f = new JFrame("Fond");
f.setSize(200, 200);
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JRadioButton b1 = new JRadioButton("Jaune");
JRadioButton b2 = new JRadioButton("Cyan");
JRadioButton b3 = new JRadioButton("Magenta");
Observer observer = new Observer();
b1.addActionListener(observer);
b2.addActionListener(observer);
b3.addActionListener(observer);
JPanel p = new JPanel();
f.add(p);
p.add(b1);
p.add(b2);
p.add(b3);
f.setVisible(true);
}
}

Binary file not shown.

BIN
APL2.1/TP10/Fond/Fond.class Normal file

Binary file not shown.

View File

@ -0,0 +1,50 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Observer implements ActionListener {
public Observer() {
}
public void actionPerformed(ActionEvent evt) {
String name = evt.getActionCommand();
JPanel f = (JPanel)((JButton)evt.getSource()).getParent();
if (name == "Jaune") {
f.setBackground(Color.YELLOW);
} else if (name == "Cyan") {
f.setBackground(Color.CYAN);
} else if (name == "Magenta") {
f.setBackground(Color.MAGENTA);
}
}
}
public class Fond {
public static void main(String[] args) {
JFrame f = new JFrame("Fond");
f.setSize(200, 200);
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(1, 3));
JButton b1 = new JButton("Jaune");
JButton b2 = new JButton("Cyan");
JButton b3 = new JButton("Magenta");
Observer observer = new Observer();
b1.addActionListener(observer);
b2.addActionListener(observer);
b3.addActionListener(observer);
f.add(b1);
f.add(b2);
f.add(b3);
f.setVisible(true);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,54 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Observer implements ActionListener {
public Observer() {
}
public void actionPerformed(ActionEvent evt) {
String name = evt.getActionCommand();
JRadioButton rb = (JRadioButton)evt.getSource();
JPanel f = (JPanel)rb.getParent();
if (name == "Jaune") {
f.setBackground(Color.YELLOW);
} else if (name == "Cyan") {
f.setBackground(Color.CYAN);
} else if (name == "Magenta") {
f.setBackground(Color.MAGENTA);
}
}
}
public class Radio {
public static void main(String[] args) {
JFrame f = new JFrame("Fond");
f.setSize(200, 200);
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JRadioButton b1 = new JRadioButton("Jaune");
JRadioButton b2 = new JRadioButton("Cyan");
JRadioButton b3 = new JRadioButton("Magenta");
Observer observer = new Observer();
ButtonGroup bg = new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3);
b1.addActionListener(observer);
b2.addActionListener(observer);
b3.addActionListener(observer);
JPanel p = new JPanel();
f.add(p);
p.add(b1);
p.add(b2);
p.add(b3);
f.setVisible(true);
}
}