Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe that the best way to do this project would be to draw the scene at regular intervals e.g. 10 milliseconds using a <code>Thread.sleep()</code>. This way, you can simply add a variable to show the message for, say, 100 loops (1 second) like this:</p> <pre><code>private LinkedList&lt;String&gt; drawStringList= new LinkedList&lt;&gt;(); private LinkedList&lt;Integer&gt; drawStringTimeout= new LinkedList&lt;&gt;(); private LinkedList&lt;Integer[]&gt; drawStringPos= new LinkedList&lt;&gt;(); public void addText(String stringToWrite, int posX, int posY, int timeOut) { drawStringList.add(stringToWrite); int[] pos = new int[2]; pos[0] = posX; pos[1] = posY; drawStringPos.add(pos); drawStringTimeout.add(timeOut); } private void mainLoop() { ...items to be drawn here... for(int i=0;i&lt;drawStringList.size();i++){ g.drawString(drawStringList.get(i),drawStringPos.get(i)[0],drawStringPos.get(i)[1]); drawStringTimeout.set(i,drawStringTimeout.get(i)-1); if(drawStringTimeout.get(i)&lt;=0) { drawStringList.remove(i); drawStringTimeout.remove(i); drawStringPos.remove(i); } } try { Thread.sleep(10); } catch (Exception e) {} } </code></pre> <p>In this code, you must add the string you want to draw to <code>drawStringList</code>, add the number of loops you want it to stay for to <code>drawStringTimeout</code> and add the position you would like to draw it in to <code>drawStringPos</code> as an array (you could use a point if you wanted to). I have made a method to do this.</p>
 

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