[5019] in java-interest
Don't get it :(
daemon@ATHENA.MIT.EDU (Michael Mehrle)
Fri Jan 26 01:50:31 1996
Date: Thu, 25 Jan 1996 21:06:09 -0700
To: java-interest@java.Eng.Sun.COM
From: michael@w3media.com (Michael Mehrle)
Everybody:
The source below actually *works* :) and I want to know why!
This source creates an offscreen graphics object, which I have a little
problem with. If you follow my comments, then you get a feeling of my
understanding of the code. I would appreciate it if you would point me the
right way. My problem is with the following commented lines:
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 HelloWorld 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; // creates offscreen Image
Graphics osGraphics; //creates offscreen Graphics
public void init(){
input_text=getParameter("text");
im=createImage(size().width,size().height); //passes boundaries to image
//no problem, this creates the -
//actual offscreen image.
osGraphics=im.getGraphics(); //passes the image to the offscreen Graphics
} // Why within the init() method? It's empty!
// What graphics is the image getting and
passing?
public void paint(Graphics g){
paintText(osGraphics); //Is this passing the offscreen image object to -
// paintText?
g.drawImage(im,0,0,null); //I'm confused! What graphics object is being
drawn?
}
public void paintText(Graphics g){ //writes the entire image to the
offscreen-
g.setColor(Color.black); //image. Why also the background?
g.fillRect(0,0,width,height);
g.clipRect(0,0,width,height); // creates clipping area - okay! Althoug I -
// commented that one and it didn't make a
// difference
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){ //overrides update(Graphics g) since
paint(g); //this is new the default paints the background of the applet.
//I'm not sure what's exactly happening here
}
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