I've got problem with displaying already drawn circles at JPanel. When I click to button to add new circle, then again and again, circles are normaly drew but whem I iconized and deiconized window then graphical context of JPanel is clear - yeah I know that beacuse after deiconized window the updateUI() metho is called so that clears content before drawn, but I thought to solve it to customize JPanel's overriden method to form like
to hold/keep JPanel's graphical context, simply to see again what I drew before iconizing the window.
don't use getGraphics() - it draws something once only, then if a repaint is required, poof! it's gone.
to further test, run your program, then open say notepad and drag it across, to cover half your circles,
now close notepad and see what happens.
your graphics should be done in paintComponent()
"When I click to button to add new circle" - this part needs to be added to a collection, then repaint() called,
where paintComponent() iterates the collection painting the circles.
Joined: Feb 01, 2009
Thank for advise to use collection to store circle before added, so I used ArrayList<Component> circleArray = new ArrayList<Component>(); and this arrays use when window iconized/deiconized then I itterates through whole arraylist to paint all them again. Your advice works fine. BUT next problem that I have is to move the circle, only little. Then add next circle, animate/move it again but to all circles drawn/painted before be displayed forever till I call repaint(X, Y, width, height) at specified place.
I wanted used Thread to make animation but once reaches code section: insertThrd.start(); [line 78 at AinmPanel.java] then run() of that class is not running and I don not why. I tried to debug but run() method does not reach....??? why??? yes, class that has Thread parameter implements interface Runnable, so please check it cause I tried many examples and I do not know why this thread do not want to fire up run() method ....vrrrrrr ...And also I want animation that new circle can come over the already drawn circle and can pass old circles, I thought to do it by g.setComposite(c); -> that I've done it and wanted to try animation to circles passes each other together but as I said I stopped at Thread initializing to make animation ...
Plese mainly check AnimPanel.java class and right to createCircle() method.There is thread that does not kicks off to run() method ??? I actually do not why. I know here is much code but I think is needed at this issue.
Please help me or paste me some example to make animation at circles and to circles drawn before be at AnimPane even I iconized window(partly iconizing problem is solved)
Joined: Jun 09, 2003
here's your AnimPanel stripped just to the thread stuff
you create and start a new thread (insertThrd), but what is it supposed to do?
where is it's run()?
(the run() in the code is linked to the 'implements Runnable')
read the constructors of Thread() and see if you can find out how to link the two.
as for the rest, I can't compile it, so I can't check it.
Joined: Feb 01, 2009
your advice did not help me when I've written exactly exactly same code even when I debugged my thread was not created with name: insertAnim as usually, it's strange, cause when I usually create threads with name, then debugg I can see names of created Threads, but now no .... whole problem is to first of all finish animation of circles and then display: System.out.println("Control sentece - This sentence must be displayed AFTER COMPLETION of animation Thread - insertThrd!!!");. Because of that I thought to create one thread and setPrioroty to 9 plus to insertThrd.jion() to all Threads waits to this thread and to firstly finish animation and after then continue, not continue until animation finish. Next code needs information/parameters about finished animated circle.
Please check my problem again, cause it's important for me. Thak you.
Joined: Jun 09, 2003
did you manage to modify my previous 'stripped' AnimPanel code to print out the message
"Control sentence - if start() reached run() method"