我知道我做错了什么,但我找不到到底是什么(漫长的一天编码)。
我需要实现粒子模拟器。我有一些课程,我需要在右键单击时创建几个发射器。
一些代码:
public final class Viewport extends JComponent implements ActionListener {
private AffineTransform transform = new AffineTransform();
private ArrayList particleList = new ArrayList();
ParticleEmitter emitter1;
private Timer timer;
double x;
double y;
public Viewport() {
particalEmitterImport();
}
public void particalEmitterImport() {
initComponents();
timer = new Timer(30, this);
emitter1 = new ParticleEmitter(3);
timer.start();
timer.setInitialDelay(0);
//repaint();
x = 0;
y = 0;
transform.setToIdentity();
}
public void particalEmitterImport(int mouseX, int mouseY) {
initComponents();
timer = new Timer(30, this);
emitter1 = new ParticleEmitter(3);
timer.start();
timer.setInitialDelay(0);
x = mouseX;
y = mouseY;
transform.setToIdentity();
}
主类:
private void viewportMouseClicked(java.awt.event.MouseEvent evt) {
Viewport vw = new Viewport();
if (SwingUtilities.isRightMouseButton(evt)) {
xMouse = evt.getX();
yMouse = evt.getY();
vw.particalEmitterImport(xMouse, xMouse);
vw.setLocation(xMouse,yMouse);
System.out.println("CLICK");
System.out.println(xMouse);
System.out.println(yMouse);
vw.setVisible(true);
}
问题是我看不到我的发射器,但在输出中我看到了我从事件中获得的所有值。