TP
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,19 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame fenetre = new JFrame();
|
||||||
|
fenetre.setSize(300, 200);
|
||||||
|
fenetre.setLocation(100, 100);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
JLabel texte = new JLabel("L'alcool c'est pas bien");
|
||||||
|
texte.setHorizontalAlignment(JLabel.CENTER);
|
||||||
|
texte.setFont(new Font("Arial", Font.BOLD, 35));
|
||||||
|
fenetre.setLayout(new BorderLayout());
|
||||||
|
fenetre.add(texte, BorderLayout.CENTER);
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-2
@@ -1,6 +1,7 @@
|
|||||||
import java.awt.Point;
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Etoile implements ProducteurDePoints {
|
public class Etoile implements ProducteurDePoints extends JComponent {
|
||||||
private static final int xCentre = 100;
|
private static final int xCentre = 100;
|
||||||
private static final int yCentre = 100;
|
private static final int yCentre = 100;
|
||||||
private static final double rayon = 90.0;
|
private static final double rayon = 90.0;
|
||||||
@@ -24,7 +25,22 @@ public class Etoile implements ProducteurDePoints {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics pinceau) {
|
||||||
|
Graphics secondPinceau = pinceau.create();
|
||||||
|
if (this.isOpaque()) {
|
||||||
|
secondPinceau.setColor(this.getBackground());
|
||||||
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
}
|
||||||
|
secondPinceau.drawRect();
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
JFrame fenetre = new JFrame();
|
||||||
|
fenetre.setSize(300, 300);
|
||||||
|
fenetre.setLocation(100, 100);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
fenetre.setVisible(true);
|
||||||
Etoile e = new Etoile();
|
Etoile e = new Etoile();
|
||||||
while (e.suivant() != null) {
|
while (e.suivant() != null) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
public interface Vehicule {
|
public interface Vehicule {
|
||||||
|
|
||||||
public String sorte();
|
public String sorte();
|
||||||
|
|
||||||
public int nbRoues();
|
public int nbRoues();
|
||||||
|
|||||||
Binary file not shown.
@@ -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.
@@ -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.
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,30 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Cercle extends JComponent {
|
||||||
|
|
||||||
|
private Color fond;
|
||||||
|
|
||||||
|
public Cercle(Color fond) {
|
||||||
|
this.fond = fond;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics pinceau) {
|
||||||
|
Graphics secondPinceau = pinceau.create();
|
||||||
|
|
||||||
|
if (this.isOpaque()) {
|
||||||
|
pinceau.setColor(this.getBackground());
|
||||||
|
pinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
pinceau.setColor(Color.DARK_GRAY);
|
||||||
|
pinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
pinceau.setColor(this.fond);
|
||||||
|
pinceau.fillOval(this.getWidth()/4, this.getHeight()/4, this.getWidth()/2, this.getHeight()/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFond(Color n) {
|
||||||
|
this.fond = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,29 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Fenetre extends JFrame {
|
||||||
|
public Fenetre() {
|
||||||
|
this.setSize(700, 100);
|
||||||
|
this.setLocation(100, 100);
|
||||||
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
this.setLayout(new GridLayout(1, 10));
|
||||||
|
|
||||||
|
Cercle[] tabCercles = new Cercle[10];
|
||||||
|
|
||||||
|
for (int i = 0; i != 5; i++) {
|
||||||
|
Cercle nouveauCercle = new Cercle(Color.ORANGE);
|
||||||
|
this.add(nouveauCercle);
|
||||||
|
tabCercles[i] = nouveauCercle;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 5; i != 10; i++) {
|
||||||
|
Cercle nouveauCercle = new Cercle(Color.LIGHT_GRAY);
|
||||||
|
this.add(nouveauCercle);
|
||||||
|
tabCercles[i] = nouveauCercle;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoletteSouris gestionSouris = new MoletteSouris(this, tabCercles);
|
||||||
|
this.addMouseWheelListener(gestionSouris);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Fenetre fenetre = new Fenetre();
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
|||||||
|
import java.awt.event.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class MoletteSouris implements MouseWheelListener {
|
||||||
|
|
||||||
|
private Fenetre fenetre;
|
||||||
|
private Cercle[] tabCercles;
|
||||||
|
private int depart;
|
||||||
|
|
||||||
|
public MoletteSouris(Fenetre fenetre, Cercle[] tabCercles) {
|
||||||
|
this.fenetre = fenetre;
|
||||||
|
this.tabCercles = tabCercles;
|
||||||
|
this.depart = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent evenement) {
|
||||||
|
int sensRotation = evenement.getWheelRotation();
|
||||||
|
this.depart -= sensRotation;
|
||||||
|
|
||||||
|
if (this.depart == 11) {
|
||||||
|
this.depart = 10;
|
||||||
|
}
|
||||||
|
else if (this.depart == -1) {
|
||||||
|
this.depart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < this.depart ; i++) {
|
||||||
|
this.tabCercles[i].setFond(Color.ORANGE);
|
||||||
|
}
|
||||||
|
for (int i = this.depart; i < 10; i++) {
|
||||||
|
this.tabCercles[i].setFond(Color.LIGHT_GRAY);
|
||||||
|
}
|
||||||
|
this.fenetre.repaint();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,34 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Fenetre extends JFrame {
|
||||||
|
public Fenetre() {
|
||||||
|
this.setLocation(100, 100);
|
||||||
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
this.setLayout(new GridLayout(14, 1));
|
||||||
|
|
||||||
|
JLabel[] chromakopia = {
|
||||||
|
new JLabel("St. Chroma"),
|
||||||
|
new JLabel("Rah Tah Tah"),
|
||||||
|
new JLabel("Noid"),
|
||||||
|
new JLabel("Darling, I"),
|
||||||
|
new JLabel("Hey Jane"),
|
||||||
|
new JLabel("I Killed You"),
|
||||||
|
new JLabel("Judge Judy"),
|
||||||
|
new JLabel("Sticky"),
|
||||||
|
new JLabel("Take Your Mask Off"),
|
||||||
|
new JLabel("Tomorrow"),
|
||||||
|
new JLabel("Thought I Was Dead"),
|
||||||
|
new JLabel("Like Him"),
|
||||||
|
new JLabel("Balloon"),
|
||||||
|
new JLabel("I Hope You Find Your Way Home")
|
||||||
|
};
|
||||||
|
|
||||||
|
for (JLabel titre : chromakopia) {
|
||||||
|
this.addMouseListener(new GestionSouris(titre));
|
||||||
|
this.add(titre);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pack();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
|||||||
|
import java.awt.event.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class GestionSouris implements MouseListener {
|
||||||
|
|
||||||
|
private JLabel titre;
|
||||||
|
|
||||||
|
public GestionSouris(JLabel titre) {
|
||||||
|
this.titre = titre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(MouseEvent evenement) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseEntered(MouseEvent evenement){
|
||||||
|
this.titre.setOpaque(true);
|
||||||
|
this.titre.setBackground(Color.CYAN);
|
||||||
|
this.titre.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseExited(MouseEvent evenement){
|
||||||
|
this.titre.setOpaque(true);
|
||||||
|
this.titre.setBackground(Color.WHITE);
|
||||||
|
this.titre.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mousePressed(MouseEvent evenement){
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent evenement){
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Fenetre fenetre = new Fenetre();
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,21 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class Acharnement extends WindowAdapter{
|
||||||
|
|
||||||
|
private int compteur;
|
||||||
|
|
||||||
|
public Acharnement() {
|
||||||
|
this.compteur = 0;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent evenement) {
|
||||||
|
if (this.compteur == 2) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.compteur++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class AcharnementMain {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame fenetre = new JFrame();
|
||||||
|
fenetre.setSize(300, 200);
|
||||||
|
fenetre.setLocation(100, 100);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
fenetre.addWindowListener(new Acharnement());
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,44 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Configuration {
|
||||||
|
|
||||||
|
private char[][] grille;
|
||||||
|
|
||||||
|
|
||||||
|
public Configuration() {
|
||||||
|
this.grille = new char[3][3];
|
||||||
|
for(char[] ligne : grille) {
|
||||||
|
Arrays.fill(ligne, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean estLibre(int x, int y) {
|
||||||
|
return this.grille[x][y] == ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Configuration jouer(int joueur, int x, int y) {
|
||||||
|
Configuration nouvelleConfig = this;
|
||||||
|
if (joueur == 1) {
|
||||||
|
nouvelleConfig.grille[x][y] = 'X';
|
||||||
|
return nouvelleConfig;
|
||||||
|
}
|
||||||
|
nouvelleConfig.grille[x][y] = 'O';
|
||||||
|
return nouvelleConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pas demandé
|
||||||
|
public char[][] getGrille() {
|
||||||
|
return this.grille;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pas demandé
|
||||||
|
public String toString() {
|
||||||
|
String resultat = "";
|
||||||
|
for (char[] ligne : this.grille) {
|
||||||
|
resultat += Arrays.toString(ligne);
|
||||||
|
}
|
||||||
|
return resultat;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
public class ConfigurationTest {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Configuration nouveau = new Configuration();
|
||||||
|
System.out.println(nouveau.estLibre(0, 0)); // Affiche bien true car la grille est vide
|
||||||
|
nouveau.jouer(1, 0, 0); // On joue dans cette case
|
||||||
|
System.out.println(nouveau.estLibre(0, 0)); // Affiche bien false car on vient de placer un joueur dans cette case
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,28 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Declinaisons extends JComponent {
|
||||||
|
|
||||||
|
private Color couleurTriangle;
|
||||||
|
|
||||||
|
public Declinaisons(Color couleurTriangle) {
|
||||||
|
super();
|
||||||
|
this.couleurTriangle = couleurTriangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics pinceau) {
|
||||||
|
Graphics secondPinceau = pinceau.create();
|
||||||
|
|
||||||
|
if (this.isOpaque()) {
|
||||||
|
secondPinceau.setColor(this.getBackground());
|
||||||
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
secondPinceau.setColor(this.couleurTriangle);
|
||||||
|
System.out.println("Width : " + this.getWidth() + " Height : " + this.getHeight());
|
||||||
|
int[] coord_x = {this.getWidth()/4, this.getWidth()/4*3, this.getWidth()/2};
|
||||||
|
int[] coord_y = {this.getHeight()/2, this.getHeight()/3, this.getHeight()/5*4};
|
||||||
|
secondPinceau.fillPolygon(coord_x, coord_y, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,22 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class DeclinaisonsMain {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame fenetre = new JFrame();
|
||||||
|
fenetre.setSize(300, 300);
|
||||||
|
fenetre.setLocation(100, 100);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
fenetre.setLayout(new GridLayout(2, 2));
|
||||||
|
JPanel[] panneaux = {new JPanel(), new JPanel(), new JPanel(), new JPanel()};
|
||||||
|
Color[] couleursTriangles = {Color.MAGENTA, Color.YELLOW, Color.CYAN, Color.BLUE};
|
||||||
|
Color[] couleursFonds = {Color.CYAN, Color.PINK, Color.MAGENTA, Color.YELLOW};
|
||||||
|
for (int i = 0; i != 4; i++) {
|
||||||
|
panneaux[i].setBackground(couleursFonds[i]);
|
||||||
|
panneaux[i].setLayout(new BorderLayout());
|
||||||
|
panneaux[i].add(new Declinaisons(couleursTriangles[i]), BorderLayout.CENTER);
|
||||||
|
fenetre.add(panneaux[i]);
|
||||||
|
}
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Duplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
double[] tab = new double[10];
|
||||||
|
Arrays.fill(tab, 5.8);
|
||||||
|
System.out.println(Arrays.toString(tab));
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user