Note that there are some explanatory texts on larger screens.

plurals
  1. POArraylist of type superclass to hold various subclass types
    primarykey
    data
    text
    <p>The functions in my classes have worked after being tested. The ColorDrop creates a falling drop of specified color. The SpeedDrop of specified speed and so forth. I want to put my drops in a list an mass produce them in the GUI. Drop is the superclass, ColorDrop and SpeedDrop are subclasses that extend the superclass. The code compile, but the GUI is blank. Am i assembling my arraylist wrong? Or am I calling methods on objects of that list incorrectly?</p> <pre><code> package advancedobject; import java.awt.Color; import java.awt.Graphics2D; import java.util.ArrayList; public class MyGooDrop extends Goo { Drop testDrop; Drop colorDrop; Drop fastDrop; Drop wavyDrop; int random = (int) Math.random()*width; ArrayList&lt;Drop&gt; drops; public MyGooDrop() { testDrop = new Drop(width/2, -10, 10); colorDrop = new ColorDrop(width/3, -10, 10, Color.BLUE); fastDrop = new SpeedDrop ( (width * 3/4), -10, 10, 5); wavyDrop = new WavyDrop (-10, height/2, 10); drops = new ArrayList&lt;Drop&gt;(); fillDropList(); } public void fillDropList () { for(int i = 0; i&lt;= 12; i++) { if (i &lt;= 4) drops.add(i, new Drop ((int) Math.random()*width, -10, 10)); else if (i&gt;4 &amp;&amp; i&lt;=8) drops.add(i, new ColorDrop ((int) Math.random()*width, -10, 10, Color.BLUE)); //drops.get(i).randomPainter() else drops.add(i, new SpeedDrop ((int) Math.random()*width, -10, 10, (int) Math.random()*10)); } } public void draw(Graphics2D g) { // Fill background g.setColor(Color.GRAY); g.fillRect(0, 0, width, height); testDrop.draw(g); colorDrop.draw(g); fastDrop.draw(g); wavyDrop.draw(g); for(int i = 0; i&lt;=12; i++) drops.get(i).draw(g); } public void update(){ testDrop.move(width, height); colorDrop.move(width, height); fastDrop.move(width, height); wavyDrop.move(width, height); for(int i = 0; i&lt;=12; i++) drops.get(i).move(width, height); } public static void main(String[] args) { MyGooDrop tester = new MyGooDrop(); tester.go(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload