Note that there are some explanatory texts on larger screens.

plurals
  1. POJava applet double buffer trouble (and loop trouble)
    primarykey
    data
    text
    <p>For some reason when I try to double buffer my Java applet it shows up a white square even though I'm not telling it to. Also if I try to put a loop in start() I get only a white screen even if repaint() is at the end.</p> <pre><code>/** * @(#)vo4k.java * * vo4k Applet application * * @author William Starkovich * @version 1.00 2009/2/21 */ import java.awt.*; import java.applet.*; import java.awt.event.*; import java.awt.image.*; public class vo4k extends Applet implements KeyListener { obj p1, e1; boolean[] keys; boolean end = false; Graphics g2d; Dimension size; Image buf; public void init() { keys = new boolean[256]; for(int i = 0; i &lt; 256; i++) keys[i] = false; addKeyListener(this); p1 = new obj(); p1.x = 0; size = getSize(); buf = createImage(size.width,size.height); g2d = buf.getGraphics(); } public void keyTyped(KeyEvent e) {} public void keyPressed(KeyEvent e) {keys[e.getKeyCode()] = true;} public void keyReleased(KeyEvent e) {keys[e.getKeyCode()] = false;} public void controls() { if(keys[KeyEvent.VK_SPACE]) end = true; if(keys[KeyEvent.VK_W]) p1.x += 10; } public void start() { // while(!end) // { // } } public void paint(Graphics g) { controls(); //g2d = (Graphics2D) g; g2d.setColor(Color.RED); g2d.fillRect(0,0,size.width,size.height); g2d.setColor(Color.BLUE); g2d.drawString("Welcome 2 Java!!", (int) 50, 60 ); //g2d.drawString("Welcome to Java!!", (int) p1.x, 60 ); g.drawImage(buf, 0, 0, this); repaint(); } } class obj { double x,y,l,a,s; } </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.
    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