Hi Gurus,

How to do double buffering in applet using scrollpanes and
canvases.....? It's very urgent please help ...

Sample Code:

import java.awt.*;
import java.awt.event.*;

/*
<applet code="ScrollPaneTest" width=500 height=200></applet>
*/

public class ScrollPaneTest extends java.applet.Applet implements
ActionListener,AdjustmentListener
{
 ScrollPane pane;
 XCanvas xcan;
 Image img;
 java.net.URL url;
 Dimension csize;
 Button send;
 TextField tf;


 public void init()
 {
  setLayout(new BorderLayout());
  csize = new Dimension(500,500);
  url = getDocumentBase();
  img=getImage(url,"SUNFLOWER.jpg");
  pane = new ScrollPane();
  send= new Button("Send");
  xcan = new XCanvas(csize);
  //xcan.setSize(500,100);
  pane.add(xcan);
  add("Center",pane);
  add("South",send);
  send.addActionListener(this);
  //add(tf=new TextField());
  int h = xcan.size().height;
  int w = xcan.size().width;
  System.out.println("height "+h+" width"+w);
  Adjustable vad = pane.getVAdjustable();
  vad.addAdjustmentListener(this);
 }

 public void actionPerformed(ActionEvent ae)
 {
  xcan.repaint();
 }

 public void adjustmentValueChanged(AdjustmentEvent e)
 {
  xcan.repaint();
 }

 public void update(Graphics g)
 {
  paint(g);

 }

}

class XCanvas extends Canvas
{
 Dimension canvassize;
 Image buffer;
 Graphics offscreen;

 public XCanvas(Dimension canvassize)
 {
  this.canvassize = canvassize;
  setSize(canvassize.width,canvassize.height);
 }

 public void paint(Graphics g)
 {
  buffer = createImage(size().width,size().height);
  offscreen = buffer.getGraphics();
  int x=10;
  int y=10;
  offscreen.drawString("This is Ashish",20,50);
  offscreen.drawString("Hello This is Vikram",20,75);
  offscreen.drawString("Hello This is Rajesh",20,100);
  offscreen.drawString("Hello This is Anup",20,125);
  offscreen.drawString("Hello This is Anup",20,150);
  offscreen.drawString("Hello This is Anup",20,175);
  offscreen.drawString("Hello This is Anup",20,200);
  g.drawImage(buffer,0,0,this);

 }

 public void update(Graphics g)
 {
  paint(g);

 }
}


--------->>>>>>-----------

Thanks in advance


Regards

Jaspret Singh

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to