Добавлена панель рисования для задания 2 ЛР5

This commit is contained in:
Victor 2013-12-02 19:23:32 +02:00
parent 8c896522a4
commit 7e6895bfab
2 changed files with 54 additions and 1 deletions

View File

@ -15,7 +15,7 @@ import javax.swing.SwingUtilities;
*/
public class PaintPanel extends JPanel {
private final List<PaintableObject> paintables;
protected final List<PaintableObject> paintables;
public PaintPanel(int width, int height) {
paintables = Collections.synchronizedList(new ArrayList<PaintableObject>());

View File

@ -0,0 +1,53 @@
package tse.lr5;
import java.awt.Graphics;
import tse.Util;
/**
* Панель рисования.
* @author aNNiMON
*/
public class PaintPanelTask2 extends PaintPanel implements Runnable {
public PaintPanelTask2(int width, int height) {
super(width, height);
}
public void startRepainterThread() {
new Thread(this).start();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
}
@Override
public void run() {
while (true) {
synchronized (paintables) {
for (PaintableObject p1 : paintables) {
FileIconPaintable f1 = (FileIconPaintable) p1;
checkCollide(f1);
}
}
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Util.handleException(ex);
}
}
}
private void checkCollide(FileIconPaintable f1) {
for (PaintableObject p2 : paintables) {
if (f1.equals(p2)) continue;
FileIconPaintable f2 = (FileIconPaintable) p2;
if (f1.isCollide(f2)) {
f1.changeRotateDirection();
return;
}
}
}
}