[5555] in java-interest
Thread problems with Mac
daemon@ATHENA.MIT.EDU (Michael Mehrle)
Thu Feb 15 21:04:01 1996
Date: Thu, 15 Feb 1996 13:30:49 -0700
To: beta@natural.com
From: michael@w3media.com (Michael Mehrle)
Cc: java-interest-digest@java.Eng.Sun.COM
The problem below is occuring on a PowerMac 8100/110 using Roaster's Applet
Runner:
This is weird. Since the 1.1 update, the ticker below doesn't resume the
thread anymore after I suspended it... Am I doing something wrong?
Also, when I try to run this class with Sun's Mac version of the Applet
Runner, it straightforwardly crashes on me. Maybe it has something to do
with the offscreen image buffer?
This is my example1.html:
<title>Tickertape</title>
<hr>
<applet code = TickerTape.class width=300 height=50> <param name="text"
value="Hi Mike, how are they hanging?">
</applet>
<hr>
<a href="TickerTape.java">The source.</a>
import java.awt.Graphics;
import java.applet.Applet;
import java.awt.Font;
import java.awt.Color;
import java.awt.Event;
import java.awt.FontMetrics;
import java.awt.Image;
public class TickerTape extends Applet implements Runnable{
String input_text;
int xpos=400;
int realLength;
int realHeight;
int width=400;
int height=40;
boolean suspended = false;
Font font= new Font("Helvetica",1,14);
Color color = new Color(0,0,255);
Thread killme=null;
Image im;
public void init(){
input_text=getParameter("text");
im=createImage(size().width,size().height);
osGraphics=im.getGraphics();
}
public void paint(Graphics g){
paintText(osGraphics);
g.drawImage(im,0,0,null);
}
public void paintText(Graphics g){
g.setColor(Color.black);
g.fillRect(0,0,width,height);
g.clipRect(0,0,width,height);
g.setFont(font);
g.setColor(color);
FontMetrics fmetrics=g.getFontMetrics();
realLength=fmetrics.stringWidth(input_text);
realHeight=fmetrics.getHeight();
g.drawString(input_text,xpos,(height+realHeight)/2);
}
public void start(){
if(killme==null){
killme=new Thread(this);
killme.start();
}
}
public void setcoord(){
xpos =xpos-5;
if(xpos<-realLength){
xpos=width;
}
}
public void run(){
while(killme != null){
try {Thread.sleep(100);}catch(InterruptedException e){}
setcoord();
repaint();
}
}
public void update(Graphics g){
paint(g);
}
public boolean handleEvent(Event evt) {
if (evt.id == Event.MOUSE_DOWN) {
if (suspended) {
killme.resume();
} else {
killme.suspend();
}
suspended = !suspended;
}
return true;
}
public void stop(){
if(killme != null)
killme.stop();
killme=null;
}
}
\\///
[ o-o ]
____________OOOo___(.)___oOOO_______________
http://www.w3media.com/w3media
michael@w3media.com
Tel. 310.441.9599
Fax 310.441.5919
"One man's mundane and desperate existence
is someone else's Technicolor."
-Strange Days-
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com