Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

Mastering the paint() and the update (Applets)

Custom Search
Mastering the paint() and the update (Applets)

[ Return to Shlurrrpp......Java ]




When to have the Update function and When Not To

When to have the Update function and When Not To


The html file should have the applet tag for the class file

a1.html

<applet code="zzz" width=350 height=250></applet>

 


The import statements for the program codes are

import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;

zzz.java

public class zzz extends Applet
{       int i = 0;
        public void init()
        {
        }
        public void paint ( Graphics g)
        {       i++;
                g.drawString("value of i "+i,1,i);
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

zzz.java

public class zzz extends Applet
{       int i = 0;
        public void init()
        {
        }
        public void paint (Graphics g)
        {       i++;
                g.drawString("value of i "+i,1,i);
        }
        public void update(Graphics g)
        {
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

zzz.java

public class zzz extends Applet
{       int i = 0;
        public void init()
        {
        }
        public void paint ( Graphics g)
        {       i++;
                g.drawString("value of i "+i,1,i);
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

zzz.java

public class zzz extends Applet
{       int i = 0;
        public void init()
        {
        }
        public void paint ( Graphics g)
        {       i++;
                g.drawString("value of i "+i,10,10);
                g.drawString("value of i "+i,10,40);
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

/*
Start Notepad while the applet window is still on. Move the notepad window
in such a way that it covers up only the entire second string .
When the notepad window is now moved out of the applet window ,
the value of i changes  for the second string only changes. Click with
the mouse , both the values of i change.
*/

zzz.java

public class zzz extends Applet
{       Image i;int j=0;
        public void init()
        {       i = getImage(getDocumentBase(),"jim.graham.gif");
        }
        public void paint ( Graphics g)
        {       g.drawImage(i,0,0,this);
                showStatus("value of j "+j++);
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

zzz.java

public class zzz extends Applet
{       Image i;int j=0;
        public void init()
        {       i = getImage(getDocumentBase(),"jim.graham.gif");
        }
        public void paint ( Graphics g)
        {       g.drawImage(i,0,0,null);
                showStatus("value of j "+j++);
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

zzz.java

public class zzz extends Applet
{       Image i;int j=0;
        public void init()
        {       i = getImage(getDocumentBase(),"jim.graham.gif");
        }
        public void paint ( Graphics g)
        {       g.drawImage(i,0,0,null);
                showStatus("value of j "+j++);
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public boolean mouseDown(Event e, int x,int y)
        {       repaint();
                return true;
        }
}

Your comments , feedback , suggestions are most welcomed. Tell us how we can improvise the tutorial.

 

Back to the Java Page


 

 

Vijay Mukhi's Computer Institute
B-13, Everest Building, Tardeo, Bombay 400 034, India.
http://www.neca.com/~vmis
e-mail : vmukhi@giasbm01.vsnl.net.in

 


[ Return to Shlurrrpp......Java ]




Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy