newbie: awt repaint

G

Guest

I want my applet to load an Imageevery 20 secs from an URL and display in a Panel.
My problem is that:
My applet loads my image but I must minimize and maximize the browser to view my image

What I can do? (Before ask, I use all of the commented lines)

My 'TimerTask' class is this:
------------------------------------------
class LoadAdv extends TimerTask {
public void run() {
try{
URL urlAdv = new URL("http://localhost/ads/adv.php?" + timeblock);
/*is class h*/ iAdv.a9 = getImage(urlAdv);
//pAdv.repaint(); // pAdv is Label
//repaint();
update(getGraphics());
}catch(Exception e){
}
timeblock++; // is int
}
}
-----class h------------------------------
public class h extends Canvas
{
public h(Image image) {a9 = image; }
public final void update(Graphics g) {paint(g);}
public final void paint(Graphics g) {g.drawImage(a9, 0, 0, this);}
public Image a9;
}
 
R

Roedy Green

I want my applet to load an Imageevery 20 secs from an URL and display in a Panel.
My problem is that:
My applet loads my image but I must minimize and maximize the browser to view my image

What I can do? (Before ask, I use all of the commented lines)

My 'TimerTask' class is this:
------------------------------------------
class LoadAdv extends TimerTask {
public void run() {
try{
URL urlAdv = new URL("http://localhost/ads/adv.php?" + timeblock);
/*is class h*/ iAdv.a9 = getImage(urlAdv);
//pAdv.repaint(); // pAdv is Label
//repaint();
update(getGraphics());
}catch(Exception e){
}
timeblock++; // is int
}
}
-----class h------------------------------
public class h extends Canvas
{
public h(Image image) {a9 = image; }
public final void update(Graphics g) {paint(g);}
public final void paint(Graphics g) {g.drawImage(a9, 0, 0, this);}
public Image a9;
}
All you need do is issue a repaint on an interval. You need a
separate thread to do that. In Swing you would use a Timer, but there
is a also a Timer class outside swing a tad harder to use. If you
want to do it a low level, you simply sleep, repaint sleep.

see http://mindprod.com/jgloss/thread.html
 
G

Guest

I want my applet to load an Imageevery 20 secs from an URL and display in a Panel.
why?
repaint is called automatically when applet must redraw.
Also, when I change the image url I call 'LabelContainsImage.redraw();'
Why I must redraw applet every 100 msecs with a thread?

Now I use this and its work!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top