Fin de tout
This commit is contained in:
parent
cf33623a5d
commit
6f2ea4a30a
DEV2.1
TP09
03_Rectangle
04_Multiple
Fenetre.classFenetre.javaGestionSouris.classGestionSouris.javaJLabel2.classJLabel2.javaMain.classMain.java
05_Balle
TP10/04_Apparences
Binary file not shown.
@ -5,14 +5,16 @@ import java.awt.*;
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private Rectangle rect;
|
||||
private JPanel rect;
|
||||
private int debutX;
|
||||
private int debutY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
private boolean rectActif;
|
||||
|
||||
public GestionSouris(Fenetre fenetre) {
|
||||
this.fenetre = fenetre;
|
||||
this.rectActif = false;
|
||||
}
|
||||
|
||||
|
||||
@ -26,32 +28,28 @@ public class GestionSouris implements MouseListener {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
if (this.rectActif) {
|
||||
this.fenetre.remove(this.rect);
|
||||
}
|
||||
System.out.println("Appui simple");
|
||||
this.fenetre.add(new Rectangle(evenement.getX(), evenement.getY(), evenement.getX()+200, evenement.getY()+200));
|
||||
this.debutX = evenement.getX();
|
||||
this.debutY = evenement.getY();
|
||||
this.rect = new Rectangle(this.debutX, this.debutY, evenement.getX(), evenement.getY());
|
||||
//this.fenetre.add(rect);
|
||||
this.rect = new JPanel();
|
||||
this.rect.setOpaque(true);
|
||||
this.rect.setBackground(Color.BLUE);
|
||||
this.debutX = evenement.getX()-4; // Le -4 est du à un décalage de la méthode getX jsp pourquoi sah
|
||||
this.debutY = evenement.getY()-26; // Pareil pour le -26
|
||||
this.fenetre.add(this.rect);
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
this.finX = evenement.getX();
|
||||
this.finY = evenement.getY();
|
||||
this.rectActif = true;
|
||||
}
|
||||
|
||||
public int getDebutX() {
|
||||
return this.debutX;
|
||||
}
|
||||
|
||||
public int getDebutY() {
|
||||
return this.debutY;
|
||||
}
|
||||
|
||||
public void setRect(int finX, int finY) {
|
||||
this.rect.setBounds(this.debutX, this.debutY, finX, finY);
|
||||
System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
|
||||
System.out.println("fin : [" + finX + ", " + finY + "]");
|
||||
System.out.println(this.debutX + " " + this.debutY + " " + (finX-this.debutX+5) + " " + (finY-this.debutY-10) + "");
|
||||
this.rect.setBounds(this.debutX, this.debutY, finX-this.debutX-4, finY-this.debutY-26); // Décalage encore
|
||||
//System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
|
||||
//System.out.println("fin : [" + finX + ", " + finY + "]");
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/03_Rectangle/Rect.class
Normal file
BIN
DEV2.1/TP09/03_Rectangle/Rect.class
Normal file
Binary file not shown.
@ -1,14 +1,14 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Rectangle extends JComponent {
|
||||
public class Rect extends JComponent {
|
||||
|
||||
private int departX;
|
||||
private int departY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
|
||||
public Rectangle(int departX, int departY, int finX, int finY) {
|
||||
public Rect(int departX, int departY, int finX, int finY) {
|
||||
this.departX = departX;
|
||||
this.departY = departY;
|
||||
this.finX = finX;
|
BIN
DEV2.1/TP09/04_Multiple/Fenetre.class
Normal file
BIN
DEV2.1/TP09/04_Multiple/Fenetre.class
Normal file
Binary file not shown.
58
DEV2.1/TP09/04_Multiple/Fenetre.java
Normal file
58
DEV2.1/TP09/04_Multiple/Fenetre.java
Normal file
@ -0,0 +1,58 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
|
||||
private JLabel2 actif;
|
||||
private boolean estActif;
|
||||
|
||||
public Fenetre() {
|
||||
this.estActif = false;
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(14, 1));
|
||||
|
||||
JLabel2[] chromakopia = {
|
||||
new JLabel2("St. Chroma"),
|
||||
new JLabel2("Rah Tah Tah"),
|
||||
new JLabel2("Noid"),
|
||||
new JLabel2("Darling, I"),
|
||||
new JLabel2("Hey Jane"),
|
||||
new JLabel2("I Killed You"),
|
||||
new JLabel2("Judge Judy"),
|
||||
new JLabel2("Sticky"),
|
||||
new JLabel2("Take Your Mask Off"),
|
||||
new JLabel2("Tomorrow"),
|
||||
new JLabel2("Thought I Was Dead"),
|
||||
new JLabel2("Like Him"),
|
||||
new JLabel2("Balloon"),
|
||||
new JLabel2("I Hope You Find Your Way Home")
|
||||
};
|
||||
|
||||
for (JLabel2 titre : chromakopia) {
|
||||
GestionSouris gestion = new GestionSouris(titre, this);
|
||||
titre.addMouseListener(gestion);
|
||||
titre.setGestionnaireSouris(gestion);
|
||||
this.add(titre);
|
||||
}
|
||||
|
||||
this.pack();
|
||||
}
|
||||
|
||||
public boolean getEstActif() {
|
||||
return this.estActif;
|
||||
}
|
||||
|
||||
public void setEstActif(boolean n) {
|
||||
this.estActif = n;
|
||||
}
|
||||
|
||||
public void setActif(JLabel2 n) {
|
||||
this.actif = n;
|
||||
}
|
||||
|
||||
public JLabel2 getActif() {
|
||||
return this.actif;
|
||||
}
|
||||
|
||||
}
|
BIN
DEV2.1/TP09/04_Multiple/GestionSouris.class
Normal file
BIN
DEV2.1/TP09/04_Multiple/GestionSouris.class
Normal file
Binary file not shown.
67
DEV2.1/TP09/04_Multiple/GestionSouris.java
Normal file
67
DEV2.1/TP09/04_Multiple/GestionSouris.java
Normal file
@ -0,0 +1,67 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private JLabel2 titre;
|
||||
private Fenetre fenetre;
|
||||
private JLabel2 actif;
|
||||
private boolean actuelEstActif;
|
||||
|
||||
public GestionSouris(JLabel2 titre, Fenetre fenetre) {
|
||||
this.titre = titre;
|
||||
this.fenetre = fenetre;
|
||||
}
|
||||
|
||||
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){
|
||||
if (!this.actuelEstActif) {
|
||||
this.titre.setOpaque(true);
|
||||
this.titre.setBackground(null);
|
||||
this.titre.repaint();
|
||||
}
|
||||
else {
|
||||
this.titre.setBackground(Color.LIGHT_GRAY);
|
||||
this.titre.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
this.titre.setBackground(Color.LIGHT_GRAY);
|
||||
this.actuelEstActif = true;
|
||||
if (!evenement.isControlDown()) {
|
||||
System.out.println("Ctrl not Pressed");
|
||||
}
|
||||
else {
|
||||
System.out.println("Ctrl Pressed");
|
||||
}
|
||||
this.titre.repaint();
|
||||
|
||||
if (this.fenetre.getEstActif() && !evenement.isControlDown()) {
|
||||
this.fenetre.getActif().setBackground(null);
|
||||
this.fenetre.getActif().getGestionnaireSouris().setActuelEstActif(false);
|
||||
this.fenetre.getActif().repaint();
|
||||
}
|
||||
|
||||
if (!evenement.isControlDown()) {
|
||||
this.fenetre.setEstActif(true);
|
||||
this.fenetre.setActif(this.titre);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void setActuelEstActif(boolean n) {
|
||||
this.actuelEstActif = n;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/04_Multiple/JLabel2.class
Normal file
BIN
DEV2.1/TP09/04_Multiple/JLabel2.class
Normal file
Binary file not shown.
19
DEV2.1/TP09/04_Multiple/JLabel2.java
Normal file
19
DEV2.1/TP09/04_Multiple/JLabel2.java
Normal file
@ -0,0 +1,19 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class JLabel2 extends JLabel {
|
||||
private GestionSouris gestionnaireSouris;
|
||||
|
||||
public JLabel2(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public void setGestionnaireSouris(GestionSouris n) {
|
||||
this.gestionnaireSouris = n;
|
||||
}
|
||||
|
||||
public GestionSouris getGestionnaireSouris() {
|
||||
return this.gestionnaireSouris;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/04_Multiple/Main.class
Normal file
BIN
DEV2.1/TP09/04_Multiple/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP09/04_Multiple/Main.java
Normal file
6
DEV2.1/TP09/04_Multiple/Main.java
Normal file
@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/Balle.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Balle.class
Normal file
Binary file not shown.
45
DEV2.1/TP09/05_Balle/Balle.java
Normal file
45
DEV2.1/TP09/05_Balle/Balle.java
Normal file
@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Balle extends JComponent {
|
||||
|
||||
private int posXImage;
|
||||
private int posYImage;
|
||||
private Graphics pinceau;
|
||||
|
||||
public Balle(int posXImage, int posYImage) {
|
||||
this.posXImage = posXImage;
|
||||
this.posYImage = posYImage;
|
||||
}
|
||||
|
||||
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.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
|
||||
Image img = Toolkit.getDefaultToolkit().getImage("terre.jpg");
|
||||
secondPinceau.drawImage(img, 0, 0, this);
|
||||
|
||||
Image balle = Toolkit.getDefaultToolkit().getImage("balle.png");
|
||||
secondPinceau.drawImage(balle, this.posXImage, this.posYImage, this);
|
||||
|
||||
this.pinceau = secondPinceau;
|
||||
}
|
||||
|
||||
public void clearComponent() {
|
||||
this.pinceau.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
public int getPosX() {
|
||||
return this.posXImage;
|
||||
}
|
||||
|
||||
public int getPosY() {
|
||||
return this.posYImage;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/Fenetre.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Fenetre.class
Normal file
Binary file not shown.
16
DEV2.1/TP09/05_Balle/Fenetre.java
Normal file
16
DEV2.1/TP09/05_Balle/Fenetre.java
Normal file
@ -0,0 +1,16 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setLocation(100,100);
|
||||
this.setSize(394,594);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(1, 1));
|
||||
Balle balle = new Balle(50, 50);
|
||||
this.add(balle);
|
||||
GestionSouris gestionSouris = new GestionSouris();
|
||||
this.addMouseListener(gestionSouris);
|
||||
this.addMouseMotionListener(new GestionnaireMouvementImage(this, balle, balle.getPosX(), balle.getPosY(), gestionSouris));
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/Fond.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Fond.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP09/05_Balle/GestionSouris.class
Normal file
BIN
DEV2.1/TP09/05_Balle/GestionSouris.class
Normal file
Binary file not shown.
43
DEV2.1/TP09/05_Balle/GestionSouris.java
Normal file
43
DEV2.1/TP09/05_Balle/GestionSouris.java
Normal file
@ -0,0 +1,43 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GestionSouris implements MouseListener {
|
||||
|
||||
private int sourisX;
|
||||
private int sourisY;
|
||||
|
||||
|
||||
public void mouseClicked(MouseEvent evenement) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent evenement){
|
||||
this.sourisX = evenement.getX()-4;
|
||||
this.sourisY = evenement.getY()-26;
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent evenement){
|
||||
}
|
||||
|
||||
public int getSourisX() {
|
||||
return this.sourisX;
|
||||
}
|
||||
|
||||
public int getSourisY() {
|
||||
return this.sourisY;
|
||||
}
|
||||
|
||||
public void setSourisX(int a) {
|
||||
this.sourisX = a;
|
||||
}
|
||||
|
||||
public void setSourisY(int b) {
|
||||
this.sourisY = b;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.class
Normal file
BIN
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.class
Normal file
Binary file not shown.
45
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.java
Normal file
45
DEV2.1/TP09/05_Balle/GestionnaireMouvementImage.java
Normal file
@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GestionnaireMouvementImage implements MouseMotionListener {
|
||||
|
||||
private Fenetre fenetre;
|
||||
private Balle balle;
|
||||
private int posX;
|
||||
private int posY;
|
||||
private GestionSouris gestionSouris;
|
||||
|
||||
public GestionnaireMouvementImage(Fenetre fenetre, Balle balle, int x, int y, GestionSouris gestionSouris) {
|
||||
this.fenetre = fenetre;
|
||||
this.balle = balle;
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.gestionSouris = gestionSouris;
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent evenement) {
|
||||
if (evenement.getX()-4 >= this.posX && evenement.getX()-4 <= this.posX+29 &&
|
||||
evenement.getY()-26 >= this.posY && evenement.getY()-26 <= this.posY+28) {
|
||||
System.out.println("I'm gonna fucking kill myself");
|
||||
this.fenetre.remove(balle);
|
||||
int diffX = (evenement.getX()-4) - this.gestionSouris.getSourisX();
|
||||
int diffY = (evenement.getY()-26) - this.gestionSouris.getSourisY();
|
||||
this.posX += diffX;
|
||||
this.posY += diffY;
|
||||
|
||||
this.gestionSouris.setSourisX(evenement.getX()-4);
|
||||
this.gestionSouris.setSourisY(evenement.getY()-26);
|
||||
Balle balle = new Balle(this.posX, this.posY);
|
||||
this.balle = balle;
|
||||
this.fenetre.add(balle);
|
||||
this.fenetre.revalidate();
|
||||
this.fenetre.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent evenement) {
|
||||
|
||||
}
|
||||
}
|
||||
|
BIN
DEV2.1/TP09/05_Balle/Main.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP09/05_Balle/Main.java
Normal file
6
DEV2.1/TP09/05_Balle/Main.java
Normal file
@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/Rect.class
Normal file
BIN
DEV2.1/TP09/05_Balle/Rect.class
Normal file
Binary file not shown.
29
DEV2.1/TP09/05_Balle/Rect.java
Normal file
29
DEV2.1/TP09/05_Balle/Rect.java
Normal file
@ -0,0 +1,29 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Rect extends JComponent {
|
||||
|
||||
private int departX;
|
||||
private int departY;
|
||||
private int finX;
|
||||
private int finY;
|
||||
|
||||
public Rect(int departX, int departY, int finX, int finY) {
|
||||
this.departX = departX;
|
||||
this.departY = departY;
|
||||
this.finX = finX;
|
||||
this.finY = finY;
|
||||
}
|
||||
|
||||
@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(Color.BLUE);
|
||||
secondPinceau.fillRect(this.departX, this.departY, this.finX-this.departX, this.finY-this.departY);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP09/05_Balle/balle.png
Normal file
BIN
DEV2.1/TP09/05_Balle/balle.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.6 KiB |
BIN
DEV2.1/TP09/05_Balle/terre.jpg
Normal file
BIN
DEV2.1/TP09/05_Balle/terre.jpg
Normal file
Binary file not shown.
After ![]() (image error) Size: 41 KiB |
Binary file not shown.
Binary file not shown.
@ -38,13 +38,13 @@ public class Fond {
|
||||
|
||||
bouton2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.MAGENTA);
|
||||
panneau.setBackground(Color.RED);
|
||||
}
|
||||
});
|
||||
|
||||
bouton3.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.YELLOW);
|
||||
panneau.setBackground(Color.MAGENTA);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user