-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyPanelDibujo.java
More file actions
144 lines (116 loc) · 2.98 KB
/
MyPanelDibujo.java
File metadata and controls
144 lines (116 loc) · 2.98 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
//dibujo vamoosh;
public class MyPanelDibujo extends JPanel implements Runnable, MouseListener, MouseMotionListener
{
private Image fondo,
pocoyo;
private int xV,
yV,
xS,
yS;
private String nombre;
private Thread hilo;
private boolean mover;
private Color colorGlobo;
private BolitaGrafica[] asteroides;
public MyPanelDibujo() {
super();
this.mover=false;
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.setPreferredSize(new Dimension(800,600));
this.fondo=new ImageIcon("planeta.jpg").getImage();
this.pocoyo=new ImageIcon("pocoyo.png").getImage();
this.xV=this.yV=0;
this.xS=70;
this.yS=515;
this.nombre="Pocoyo";
this.asteroides=new BolitaGrafica[20];
for (int i = 0; i < this.asteroides.length; i++) {
this.asteroides[i]=new BolitaGrafica();
}
this.hilo=new Thread(this);
this.hilo.start();
colorGlobo=Color.RED;
}
private void dibujaCabina(Graphics g){
g.setColor(Color.ORANGE);
g.fillOval(this.xV+50, this.yV+450, 200, 100);
g.setColor(Color.CYAN);
g.fillArc(this.xV+50, this.yV+450, 200, 100, 0, 110);
}
private void dibujaAsteroides(Graphics g) {
for (int i = 0; i < asteroides.length; i++) {
this.asteroides[i].pinta(g);
}
}
private void dibujaGlobo(Graphics g) {
g.setColor(Color.BLACK);
g.drawLine(this.xV+100, this.yV+457,this.xV+100,this.yV+400);
g.setColor(colorGlobo);
g.fillOval(this.xV+50, this.yV+300, 100, 100);
}
public void paintComponent(Graphics g) {
g.drawImage(this.fondo, 0, 0, this.getWidth(), this.getHeight(), this);
g.drawImage(this.pocoyo, this.xV+160, this.yV+460, 40,40,this);
this.dibujaCabina(g);
this.dibujaGlobo(g);
g.setColor(Color.BLACK);
g.drawString("Vamos "+this.nombre+"!",this.xS,this.yS);
this.dibujaAsteroides(g);
}
public void setNombre(String nombre) {
this.nombre=nombre;
this.repaint();
}
public void setYv(int yV){
this.yV=yV;
this.repaint();
}
public void setColorGlobo(Color colorGlobo) {
this.colorGlobo=colorGlobo;
this.repaint();
}
public void run(){
while(this.xV<=550){
try {
Thread.sleep(10);
if(this.mover) {
this.xV+=2;
this.yV--;
this.repaint();
}
}catch(InterruptedException ex) {
System.out.println("No pude despertar!");
}
}
}
public void mouseClicked(MouseEvent e) {
this.mover=true;
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent evt) {
this.xS=evt.getX();
this.yS=evt.getY();
this.repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
}