-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStar.java
More file actions
123 lines (96 loc) · 2.6 KB
/
Star.java
File metadata and controls
123 lines (96 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
// classe de l'ecran de l'application
class EcranStar extends JPanel {
static final int WIDTH = 600;
static final int HEIGHT = 400;
static final Color couleurBord = Color.red;
static final Color couleurInterieur = Color.blue;
static final Color couleurFond = Color.black;
int a, b;
int xStar[];
int yStar[];
private Polygon poly;
EcranStar() {
xStar = new int[12];
yStar = new int[12];
poly = new Polygon(xStar, yStar, 12);
setPreferredSize(new Dimension(WIDTH, HEIGHT));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawPolygon(poly);
}
public void init_a_b(int a, int b){
this.a = a;
this.b = b;
}
public void dessiner(int x, int y){
xStar[0] = (a+x)/2;
yStar[0] = b;
xStar[10] = x;
yStar[10] = (3*b+y)/4;
xStar[2] = a;
yStar[2] = (3*b+y)/4;
xStar[1] = ((xStar[10] + xStar[2])*2)/3;
yStar[1] = (3*b+y)/4;
xStar[3] = (xStar[1]+xStar[2])/2;
yStar[3] = (b + y)/2;
xStar[4] = a;
yStar[4] = (b + 3*y)/4;
xStar[6] = (a+x)/2;
yStar[6] = y;
xStar[5] = ((xStar[10] + xStar[2])*2)/3;
yStar[5] = (b + 3*y)/4;
xStar[8] = x;
yStar[8] = (b+3*y)/4;
xStar[7] = (xStar[10] + xStar[2])/3;
yStar[7] = (b+3*y)/4;
xStar[9] = (xStar[7]+xStar[8])/2;
yStar[9] = (b+y)/2;
xStar[11] = (xStar[10] + xStar[2])/3;
yStar[11] = (y+3*b)/4;
poly = new Polygon(xStar, yStar, 12);
}
}
class ControllerStar extends MouseInputAdapter implements ActionListener {
static final int ENTREE = 0, REMPL = 1;
EcranStar ecran;
int x0, y0, xc, yc;
int mode;
ControllerStar(EcranStar ecran) {
this.ecran = ecran;
}
public void actionPerformed(ActionEvent e) {}
public void mousePressed(MouseEvent e) {
ecran.init_a_b(e.getX(), e.getY());
}
public void mouseReleased(MouseEvent e) {
System.out.println("Released");
}
public void mouseDragged (MouseEvent e) {
ecran.dessiner(e.getX(), e.getY());
ecran.repaint();
}
}
public class Star{
public static void main(String[] args) {
EcranStar ecran = new EcranStar();
ControllerStar controller = new ControllerStar(ecran);
ecran.addMouseListener(controller);
ecran.addMouseMotionListener(controller);
Box box = new Box(BoxLayout.Y_AXIS);
JFrame mainFrame = new JFrame();
box = new Box(BoxLayout.X_AXIS);
box.add(ecran);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.getContentPane().add(box);
mainFrame.pack();
mainFrame.setVisible(true);
}
}