Re: Printing after an Event, from the Browser...
I am sorry ma'm. I apologize. I misunderstood your question..
Hopefully this will solve your problem...
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MyApplet extends Applet{
int[] x = { 10 , 50 , 88 };
int[] y = { 100 , 130 , 30 };
Polygon p;
int X = 0;
int Y = 0;
boolean isMouseOver;
Image img;
public void init(){
img = createImage( this.getBounds().width , this.getBounds().height );
p = new Polygon( x,y,3);
this.addMouseMotionListener( new MouseMotionAdapter(){
public void mouseMoved( MouseEvent e ){
if( p.contains( e.getX() , e.getY() )){
isMouseOver = true;
X+= 10 ;
Y+=10;
repaint();
}else{
isMouseOver = false;
}
}
});
}
public void paint( Graphics g ){
img.getGraphics().fillPolygon(p);
if( isMouseOver ){
img.getGraphics().drawString( "Poochi" , X , Y );
}
g.drawImage( img , 0 , 0 , this );
}
public void update( Graphics g ){
paint( g );
}
}
I tested this code. I am getting the printout( from the printer ) with the text "Poochi".
Basically , if you say print , the paint method will be called and that will paint on the
printer instead of screen. In your case you draws Polygon and ,since the isMouseOver is
false , it skips drawString line. Even though if it comes inside the if condition , you will
get only one text. So u are getting the Polygons only.
And , I am wondering , If you press ALT + TAB , what happend ? All the text which you
Printed on the screen would have been erased and you would have got the polygons only in the screen.
Am i correct ? Because of the reason i mentioned above. If you use my solution , you wont
get this problem. If you still haveing any problem , post it. Tell me whether it works or not.
Best of luck...
Poochi..
Re: Printing after an Event, from the Browser...
Hi,
I tried the Image object and I am able to get the text to be Printed ( printout for those that might get confused :-) ) from NETSCAPE!
But IE won't print it!
I have been using IE for all these tests and I was getting frustrated.
Another thing with IE is that the background of the Image is gray. I tried setting the img.getGraphics.setFont(Color.white), but no change. Of course without the Image, I could use the setBackground(Color.white) to change it to white.
And one thing to point out with your code -
use Graphics i = img.getGraphics();
and use object "i" each time to draw polygon/text etc. Otherwise, it gets reinstantiated.
Anyway, you get my 10 points!
Thanks a lot!
Uma.
Re: Printing after an Event, from the Browser...
> Another thing with IE is that the background of the Image is gray. I tried setting the
> img.getGraphics.setFont(Color.white), but no change. Of course without the Image, I could use the
> setBackground(Color.white) to change it to white.
That is not the background color of the Image. It's the background color of the Applet.
Still you can change the background color of the Applet using setBackground( Color.white )
method. Put it in your init() function.
> But IE won't print it!
Yes , just now i noticed it. I was trying to print from appletviewer. I hate these browsers.
And , thanks for those points. This the first time i am getting points in this forum. :-)
P.S : Are u working for 24 hours ? :-)
Re: Printing after an Event, from the Browser...
>That is not the background color of the Image. It's the background color of the Applet.
>Still you can change the background color of the Applet using setBackground( Color.white )
>method. Put it in your init() function.
I had the setBackground(Color.white) in the init() method of the Applet but it was after the createImage() method call and so it didn't update the background. Then I changed it to be above that line and it worked!
>P.S : Are u working for 24 hours ? :-)
Actually, I had this doubt about you!
Uma