|
|
@ -8,12 +8,8 @@ package cancergrowth;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Image;
|
|
|
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
import javax.swing.Timer;
|
|
|
|
import javax.swing.Timer;
|
|
|
|
import javax.swing.event.ChangeEvent;
|
|
|
|
import javax.swing.event.ChangeEvent;
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
@ -24,12 +20,12 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
private int delay;
|
|
|
|
private int delay;
|
|
|
|
private boolean growing = false;
|
|
|
|
private boolean growing = false;
|
|
|
|
private int count = 0;
|
|
|
|
private int count = 0;
|
|
|
|
private boolean draw = false;
|
|
|
|
private boolean kill = false;
|
|
|
|
|
|
|
|
private int pacmanx, pacmany;
|
|
|
|
|
|
|
|
private int cycle;
|
|
|
|
|
|
|
|
private boolean cycledir = true;
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Cell> cells = new ArrayList<Cell>(10000000);
|
|
|
|
ArrayList<Cell> cells = new ArrayList<Cell>(100000000);
|
|
|
|
|
|
|
|
|
|
|
|
Graphics g2;
|
|
|
|
|
|
|
|
Image canvas;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CellPanel()
|
|
|
|
public CellPanel()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -51,6 +47,8 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
delay = speed.getValue();
|
|
|
|
delay = speed.getValue();
|
|
|
|
swingTimer = new Timer(delay, this);
|
|
|
|
swingTimer = new Timer(delay, this);
|
|
|
|
//swingTimer.start();
|
|
|
|
//swingTimer.start();
|
|
|
|
|
|
|
|
pacmanx = 1050;
|
|
|
|
|
|
|
|
pacmany = -20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -73,14 +71,14 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
for (int k = 0; k < cells.size(); k++)
|
|
|
|
for (int k = 0; k < cells.size(); k++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Cell t = cells.get(k);
|
|
|
|
Cell t = cells.get(k);
|
|
|
|
Cell rec = t.performTime();
|
|
|
|
Cell rec = t.performTime(!kill);
|
|
|
|
if (t != rec) {
|
|
|
|
if (t != rec) {
|
|
|
|
cells.add(rec);
|
|
|
|
cells.add(rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//g2.drawImage(t.getImage(), t.getX(), t.getY(), this);
|
|
|
|
//g2.drawImage(t.getImage(), t.getX(), t.getY(), this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
growing = true;
|
|
|
|
//growing = true;
|
|
|
|
count ++;
|
|
|
|
if(!kill) count ++;
|
|
|
|
//System.out.println("ACTION PERFORMED");
|
|
|
|
//System.out.println("ACTION PERFORMED");
|
|
|
|
super.repaint();
|
|
|
|
super.repaint();
|
|
|
|
|
|
|
|
|
|
|
@ -107,15 +105,39 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
//g.setColor(t.getColor());
|
|
|
|
//g.setColor(t.getColor());
|
|
|
|
g.fillOval(t.getX(), t.getY(), 50, 50);
|
|
|
|
g.fillOval(t.getX(), t.getY(), 50, 50);
|
|
|
|
} else*/
|
|
|
|
} else*/
|
|
|
|
//if (draw || cells.size() > 10000000) {
|
|
|
|
//if (cells.size() > 10000000) {
|
|
|
|
g.drawImage(t.getImage(), t.getX(), t.getY(), this);
|
|
|
|
if(kill && (Math.abs(pacmanx + 40 - t.getX()) < 50) && (Math.abs(pacmany + 25 - t.getY()) < 75)) {
|
|
|
|
|
|
|
|
cells.remove(t);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else g.drawImage(t.getImage(), t.getX(), t.getY(), this);
|
|
|
|
|
|
|
|
|
|
|
|
//swingTimer.stop();
|
|
|
|
//swingTimer.stop();
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(kill) {
|
|
|
|
|
|
|
|
//swingTimer.setDelay(100);
|
|
|
|
|
|
|
|
g.setColor(Color.YELLOW);
|
|
|
|
|
|
|
|
g.fillArc(pacmanx, pacmany, 100, 100, 220 - cycle * 2, 280 + cycle * 4);
|
|
|
|
|
|
|
|
if (pacmanx > -100) {
|
|
|
|
|
|
|
|
pacmanx -= 10;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
pacmanx = 1050;
|
|
|
|
|
|
|
|
pacmany += 100;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cycledir) cycle ++;
|
|
|
|
|
|
|
|
else cycle --;
|
|
|
|
|
|
|
|
if (cycle == 21) cycledir = false;
|
|
|
|
|
|
|
|
if (cycle == 0) cycledir = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pacmany > 1050) {
|
|
|
|
|
|
|
|
while (!cells.isEmpty()) {
|
|
|
|
|
|
|
|
cells.remove(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
kill = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
jLabel1.setText("Delay: " + delay + "ms. Hours since start: " + count + ". Cell Count: " + cells.size());
|
|
|
|
jLabel1.setText("Delay: " + delay + "ms. Hours since start: " + count + ". Cell Count: " + cells.size());
|
|
|
|
System.out.println("Cell Count: " + cells.size());
|
|
|
|
System.out.println("Cell Count: " + cells.size());
|
|
|
|
growing = false;
|
|
|
|
//growing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -126,13 +148,14 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
* always regenerated by the Form Editor.
|
|
|
|
* always regenerated by the Form Editor.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
|
|
private void initComponents()
|
|
|
|
private void initComponents()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
speed = new javax.swing.JSlider();
|
|
|
|
speed = new javax.swing.JSlider();
|
|
|
|
jLabel1 = new javax.swing.JLabel();
|
|
|
|
jLabel1 = new javax.swing.JLabel();
|
|
|
|
jButton1 = new javax.swing.JButton();
|
|
|
|
jButton1 = new javax.swing.JButton();
|
|
|
|
|
|
|
|
jButton2 = new javax.swing.JButton();
|
|
|
|
|
|
|
|
|
|
|
|
speed.setMaximum(1000);
|
|
|
|
speed.setMaximum(1000);
|
|
|
|
speed.setMinimum(1);
|
|
|
|
speed.setMinimum(1);
|
|
|
@ -160,6 +183,16 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jButton2.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
|
|
|
|
|
|
|
|
jButton2.setText("Kill");
|
|
|
|
|
|
|
|
jButton2.addActionListener(new java.awt.event.ActionListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
jButton2ActionPerformed(evt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
|
|
|
|
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
|
|
|
|
this.setLayout(layout);
|
|
|
|
this.setLayout(layout);
|
|
|
|
layout.setHorizontalGroup(
|
|
|
|
layout.setHorizontalGroup(
|
|
|
@ -169,7 +202,9 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
.add(speed, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
.add(speed, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.add(jLabel1)
|
|
|
|
.add(jLabel1)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 662, Short.MAX_VALUE)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 593, Short.MAX_VALUE)
|
|
|
|
|
|
|
|
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.add(jButton1)
|
|
|
|
.add(jButton1)
|
|
|
|
.add(18, 18, 18))
|
|
|
|
.add(18, 18, 18))
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -180,33 +215,47 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
|
|
|
|
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
|
|
|
|
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
|
|
|
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
|
|
|
.add(jLabel1))
|
|
|
|
.add(jLabel1)
|
|
|
|
|
|
|
|
.add(jButton2))
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, speed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, speed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
|
.addContainerGap(967, Short.MAX_VALUE))
|
|
|
|
.addContainerGap(959, Short.MAX_VALUE))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}// </editor-fold>
|
|
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
|
|
|
|
|
|
|
|
private void speedMouseReleased(java.awt.event.MouseEvent evt)
|
|
|
|
private void speedMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_speedMouseReleased
|
|
|
|
{
|
|
|
|
{//GEN-HEADEREND:event_speedMouseReleased
|
|
|
|
// TODO add your handling code here:
|
|
|
|
// TODO add your handling code here:
|
|
|
|
delay = speed.getValue();
|
|
|
|
delay = speed.getValue();
|
|
|
|
//swingTimer.setDelay(1000);
|
|
|
|
//swingTimer.setDelay(1000);
|
|
|
|
super.repaint();
|
|
|
|
super.repaint();
|
|
|
|
}
|
|
|
|
}//GEN-LAST:event_speedMouseReleased
|
|
|
|
|
|
|
|
|
|
|
|
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
|
|
|
|
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
|
|
|
|
{
|
|
|
|
{//GEN-HEADEREND:event_jButton1ActionPerformed
|
|
|
|
// TODO add your handling code here:
|
|
|
|
// TODO add your handling code here:
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
swingTimer.start();
|
|
|
|
swingTimer.start();
|
|
|
|
|
|
|
|
}//GEN-LAST:event_jButton1ActionPerformed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
|
|
|
|
|
|
|
|
{//GEN-HEADEREND:event_jButton2ActionPerformed
|
|
|
|
|
|
|
|
// TODO add your handling code here:
|
|
|
|
|
|
|
|
if(kill) {
|
|
|
|
|
|
|
|
kill = false;
|
|
|
|
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
kill = true;
|
|
|
|
|
|
|
|
swingTimer.setDelay(25);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}//GEN-LAST:event_jButton2ActionPerformed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Variables declaration - do not modify
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
|
|
private javax.swing.JButton jButton1;
|
|
|
|
private javax.swing.JButton jButton1;
|
|
|
|
|
|
|
|
private javax.swing.JButton jButton2;
|
|
|
|
private javax.swing.JLabel jLabel1;
|
|
|
|
private javax.swing.JLabel jLabel1;
|
|
|
|
private javax.swing.JSlider speed;
|
|
|
|
private javax.swing.JSlider speed;
|
|
|
|
// End of variables declaration
|
|
|
|
// End of variables declaration//GEN-END:variables
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|