Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating my Graphics
    primarykey
    data
    text
    <p>I'm just starting to learn about programming in Java and even more recently with graphics, and I've run into some problems. I want to create a game like dwarf fortress in look, with colored text instead of images.</p> <p>This is what I have so far:</p> <pre><code>public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); for (int i = 0; i &lt; 50; i++) { g.drawString("[Game goes here]", 100, 150); g.dispose(); System.out.println(i); } g.dispose(); } public GTest() { setSize(Toolkit.getDefaultToolkit().getScreenSize().width / 3, Toolkit .getDefaultToolkit().getScreenSize().width / 3 + 50); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { GTest myWindow = new GTest(); } </code></pre> <p>I want it to update the graphics on a timer, but I'm not really sure how to do this. </p> <p>I know that this is a pretty broad question and I would be happy to clarify anything you might want to know. </p> <p>EDIT:</p> <p>So I added this bit:</p> <pre><code>String[] letters = new String[10]; float fontsize = Toolkit.getDefaultToolkit().getScreenSize().width / 30; public void paint(Graphics g) { g.setColor(textColor); setFont(getFont().deriveFont(fontsize)); for(int i = 0; i &lt; 10; i++){ if((int) (Math.random() * 100) &gt; 97){ letters[i] = "w"; textColor = new Color(0, 0, 100); }else{ letters[i] = "l"; textColor = new Color(0, 100, 0); } g.drawString(letters[i], i * 3, 10); } </code></pre> <p>But now it doesn't display at all. I added a sysout after the g.drawString and it performed it so I'm not sure what the problem is.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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