File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Matisse designer_problem with displaying drawn circle at JPanel/also animation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Matisse designer_problem with displaying drawn circle at JPanel/also animation problem" Watch "Matisse designer_problem with displaying drawn circle at JPanel/also animation problem" New topic
Author

Matisse designer_problem with displaying drawn circle at JPanel/also animation problem

Marian Kubincanek
Greenhorn

Joined: Feb 01, 2009
Posts: 7
Ola,

I created simply simply GUI by Matisse editor.GUI contents of JFrame and this JFrame contents one (for)JButton+JPanel and one JButton(for)+JFrame and one JButton(for)+Canvas.

I would like to ask to help me with displaying new component-drawn circle to JPanel after iconizing and deiconizing application window.
The core of the problem is that after I clicked JButton=>JButton1 , the circle instance is created, then just exactly painted to platno_jPanel1 Swing's containers and added to this container.
Very similar manner I tried to paint right to main JFrame. On each action of clicked JButton I add circle to either platno_jPanel1 or JFrame, canvas too.
The painting of circle is right but when I iconize/deiconize window then content of either JPanel, main JFrame or Canvas is clear, without circles I drow before, BUT I'will need this content be displayed after each deiconizing!!! Sucks, I am out of my mind and actually need help.
This is application si very simply, next application is based on this drawing but plus moving these circle aj JPanel----> animation. New problem I explored at animation is that when I drow one circle, and then next new circle but animating over the one before, clearing the old one---> during animation I used setClip() then repaint(x,y,xsize, ysize) but because of clearing the circles before I could not continue at this way, but I even would like to see solution like in this one animation that I found on internet(at the same I working but at GUI app)---->http://webpages.ull.es/users/jriera/Docencia/AVL/AVL%20tree%20applet.htm or http://www.engin.umd.umich.edu/CIS/course.des/cis350/treetool/index.html

Please be so kind and check attachment of simple drawing circle.

I pesonally think is really less stuff on internet according to Matisse and paint/repaint af Swing applications.

Please please help ....


Create new project, add JForm JFrame file, paste code GUI.java! new class calls Circle.java, so simply add new class file to created project and paste below code named Circle.java. Maybe, now I am too exact but really need help with repaint()ing after de/iconizing the window.!!



this code is Circle.java

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
I would advise against using getGraphics to get the graphics content and paint with it. By doing this, your component will lose this graphics context when it is repainted and so this will only result in the temporary solution you are seeing. To fix this, you need to place your new JPanel into the other component in such a way that it will be visible, and let the new JPanel draw with the Graphics object passed to its paintComponent (not paint) method. The real answer is this: before you try to do painting in Swing you must read up on Swing painting in the Sun Swing tutorials, and also read up on using the layout managers so that you can add components and they will be visible. Also, don't draw directly on the JFrame. Instead if you wish to do something like this, draw in the JPanel that is the JFrame's contentPane. Also, you'll not want to mix AWT components (Canvas) with Swing components (everything else).

For instance:

CirclePanel.java


ShowCircle.java


I'm firmly convinced that if you are learning Swing (and aren't we all?) using NetBeans to generate Swing code will hinder your Swing education by months. If you really want to code Swing well, code it by hand and go through the Sun Swing tutorials. Then when you feel quite comfortable with the Swing underpinnings (and I don't feel quite there yet), go ahead and use NetBeans for quick and dirty GUI production.

Best of luck.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
OK, I played with the CirclePanel to allow animation and placed it into a Matisse-generated app. The key here is to place my CirclePanel's JPanel into a Matisse JPanel after setting the Matisse JPanel's layout to BorderLayout (via its properties). This lets my CirclePanel's JPanel fill up the Matisse JPanel.

CirclePanel.java


Gui3.java


Lord, Matisse makes code that is ugly and hard to read!
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
I pesonally think is really less stuff on internet according to Matisse and paint/repaint af Swing applications.

You seem to have given up on this thread, and that's too bad as there's much to be learned here. Anyway I've been thinking on this, and I think that there is a very good reason for this. At least in my mind there really is no way to know how to paint or animate in Matisse without knowing how to do it in a non-Matisse Swing app. Matisse is nothing more than a tool for creating Swing code, and so painting in "Matisse" will be nothing more than painting in Swing. This is one of the reasons I suggest that you get rid of the use of Matisse when learning GUI and dive directly into Swing coding. You will learn so much at such a fast rate, all things that can be eventually and easily used in Matisse projects if desired. As always, YMMV.

Hope to see you back here.

Pete
Marian Kubincanek
Greenhorn

Joined: Feb 01, 2009
Posts: 7
Hej Pete,
I am really glad that you posted me the helpful code. It is exactly what I needed but truly said, I need to read and get practise of whole Java tutorial and AWT/Swing. simply said i gonna take a deep reading at. Yeah, I just read the book about AWT and tried several programs at netbeans, but I thought that this animation is gonna be easy but not...I have to more read about it and practise. Surely, I visit here again . Frankly, I am glad that you bring me light at my problem.
Marian Kubincanek
Greenhorn

Joined: Feb 01, 2009
Posts: 7
Hey,

I worked on GUI application to animate Binary searching tree with inserting, searching, deleting animation and these dato to be stored.
I have got problem with animating during inserting code section, so I do not have problem with data storing but with animation to be started, finished and after the new element be stored to data tree structure( so example: root = new BSTNode<T>(value, SX, SY). SX, SY are final coordinates of FINISHED new circle that extends JComponent. PLEASE as first check this link:http://www.engin.umd.umich.edu/CIS/course.des/cis350/treetool/index.html
to know how inserting to BST tree works. I think I can not uses Timers or Thread for animationg cause algorithm at class BST.java - method insert() otherwise invokes Timer, but this starts when GUI is displayed, but when you check insert() method next step after animating first element of tree is creating data root of BST tree that needs SX, SY of finished animated element.
Simply said, check BST.java - insert() method and BSTAnimation.java code. If you think you solve this problem try to iconoze/deiconized window after adding several new elemnts, cause I tried but unseccesfully

Please, help me, help me cause insert animation of new elements is hell for me, but data storing is simply ... I need help asap. If I can help, copy and paste below code and try how it works, and best would be if you add code exactly to class BST.java to insert() where is comment
like //need animation to right
//??? CODE

and class BSTAnimation.java. Please help me with insert animation for new tree elements, cause I tried simply animation, but did not find animation example for my case.

GUI.java


GUIView.java



BST.java


BSTNode.java



BSTAnimation
Marian Kubincanek
Greenhorn

Joined: Feb 01, 2009
Posts: 7
Please help me with keeping Components at JPanel and with animation. Thank much, indeed.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Please help me with keeping Components at JPanel and with animation.

a quick add indicates 1000+ lines of code in the classes, which is way too much to wade through.

you need to identify the specific problem area and build a separate program around that, then post that small program.

e.g.
does the JMenu have anything to do with the problem? if not, get rid of it
are 'all' of the buttons/labels part of the problem? if not, get rid of them (retain only those that are part of the problem)
if you're now down to just a few components, use the default layoutManager - not everyone has GroupLayout

if you can get the code down to <100 lines, more people will look at it
(and for this exercise it's probably better to put it all in a single .java file)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Matisse designer_problem with displaying drawn circle at JPanel/also animation problem