[JAVA] applet mit drawString mal kurz anhalten

Transmitter

Erfahrenes Mitglied
hi!

ich bastel gerade ein kleines applet und will das mittendrinn mal kurz anhalten.

also so ungefähr:

for schleife
var.drawString ( "String", x, y );
// hier will ich das programm kurz anhalten
// delay und sleep klappt irgendwie nicht so richtig :(
end for schleife

und sleep und delay hab ich schon probiert .. aber das ist irgendwie nur für threads? :(
ich möchte das innerhalb von
paint ( Graphics )
machen .. geht das irgendwie?

thx schon mal
cu - transmitter
 
Servus!

Schau mal hier:

Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;


/*
 * myApplet.java
 *
 * Created on 29. April 2003, 19:26
 */

/**
 *
 * @author  Administrator
 */
public class myApplet extends java.applet.Applet implements Runnable{
    
    
    Thread myDaemon;
    boolean myDaemonSleep = false;
    int i = 0;
    
    public myApplet(){
        
    }
    /** Initialization method that will be called after the applet is loaded
     *  into the browser.
     */
    public void init() {
        this.setSize(320,240);
        //this.addMouseListener(this);
    }
    
    public void start(){
        
        System.out.println("START!");
        if(this.myDaemon == null){
            this.myDaemon = new Thread(this);
            this.myDaemon.start();
        }
    }
    
    public void paint(Graphics g){
        
        i = i%319;
        g.setColor(Color.black);
        g.fillRect(i,35,35,20);
        
        try {
            Thread.sleep(100);
            
            
        }catch (InterruptedException e){
        }
        
        i++;
        
    }
    
    public synchronized void stop() {
        
        myDaemon.stop();
        myDaemon = null;
    }
    
    public boolean mouseDown(java.awt.Event evt, int x, int y) {
        if (this.myDaemonSleep) myDaemon.resume();
        else myDaemon.suspend();
        
        this.myDaemonSleep = !this.myDaemonSleep;
        return true;
    }
    public void run() {
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
        while(myDaemon != null) {
            repaint();
            
        }
    }
    
}

Gruss Tom
 
kommt in meinem buch sowieso in 50 seiten drann .. das wird sich nicht vermeiden lassen ;)

aber wenns keine andere möglichkeit gibt, werde ich das programm erst noch mal auf eis legen ;) :(
 
Zurück