Simple Problem

I am trying to draw some objects in an applet, instead of retaining the old objects, it removes the earlier ones & draws the new ones, can anyone suggest me a method by which I can retain the old images in the applet. I am attaching a simple java applet.

Sample Code :

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

import java.util.*;

public class appl1 extends Applet

{

int top,left,x1;

public void init()

{

top = 100;

left = 200;

repaint();

left = 300;

repaint();

left = 400;

repaint();

}

public void paint(Graphics g)

{

update(g);

}

public void update(Graphics g)

{

g.drawRect(200,100,300,200);

g.drawRect(left,top,100,100);

}

}

[831 byte] By [rahul420a] at [2007-9-27 9:56:25]
# 1
im not entirely sure i understood the question, but cant you put the old objects (images) into a vector or arraylist before they are overwritten?
tobysavillea at 2007-7-8 23:43:27 > top of Java-index,Archived Forums,Java Programming...
# 2

Hi Rahul420,

In your code, the method repaint() did not make any change when I commented. See the link I have given down to the reason.

public void init()

{

top = 100;

left = 200;

//repaint();

left = 300;

//repaint();

left = 400;

//repaint();

}

The values in 'left' keep changing which does not give purpose in your program. Finally, top = 100 and left is 400. With these values set, you are moving to,

public void paint(Graphics g)

{

update(g);

}

public void update(Graphics g)

{

g.drawRect(200,100,300,200);

g.drawRect(left,top,100,100);

}

Hence you are getting the result.

Now, tell what you wish to do. If you have doubt, please put more explanations to your question.

I would also suggest you to read the following.

http://java.sun.com/docs/books/tutorial/applet/index.html

http://java.sun.com/docs/books/tutorial/essential/threads/lifecycle.html

Hope this helps you,

Rajesh

fun_rajesha at 2007-7-8 23:43:27 > top of Java-index,Archived Forums,Java Programming...