The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Static Members

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Sample Code

Posted by Vikas on February 13, 2002 at 4:53 PM

HI Siva,

Thanks to Markus.

Following is the Code:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.applet.*;
import java.awt.*;


public class SimpleApplet extends Applet{

private Image Buffer;
private Graphics gBuffer;

String text = "I'm a simple applet Test";

public void init() {
//create graphics buffer, the size of the applet
text = "I'm a simple applet";
setBackground(Color.cyan);
}
public void start() {
System.out.println("starting...");
}
public void stop() {
System.out.println("stopping...");
}
public void destroy() {
System.out.println("preparing to unload...");
}
public void paint(Graphics g){
// Commented Non Working Code
// System.out.println("Paint");
// g.setColor(Color.blue);
// g.drawRect(0, 0, getSize().width -1,getSize().height -1);
// g.setColor(Color.red);
// g.drawString(text, 15, 25);
//

System.out.println("Paint");
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
gBuffer.setColor(Color.blue);
gBuffer.drawRect(0, 0,
getSize().width -1,
getSize().height -1);
gBuffer.setColor(Color.red);
gBuffer.drawString(text, 15, 25);
g.drawImage (Buffer,0,0, this);
}
}

Vikas.


> Hi Markus:
> I would appreciate if you can give a sample code.

> Thanks<
> Siva
> > Normally, if you print a page with an applet, IE calls paint ( first it calls printAll, which calls paint ) an prints the Applet with the output of paint(). But there seems to be a lot of bugs in some IE-Versions, which ignore Commands like setColor an that draw only white Rectangle or Polygons. A bad workaround, which functions, is draw all in an Image-Object and then call drawImage to draw the Image in the Graphics Object.

> > - Markus
> > Bonn, Germany





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us