Добавлена панель рисования для задания 2 ЛР5
This commit is contained in:
parent
8c896522a4
commit
7e6895bfab
@ -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>());
|
||||
|
53
src/tse/lr5/PaintPanelTask2.java
Normal file
53
src/tse/lr5/PaintPanelTask2.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user