Solved

Urgent : Overlapping JInternalFrame + JPanel

Posted on 2001-07-10
2
861 Views
Last Modified: 2012-05-04
Dear Expert,
   I got a problem and here is the complete details of the problem.
   I have a Jwindow and in that i will show some drawings.
Then i have a JPanel over it and in that panel i will do some animation.
  Then i have a JInternalFrame and which has some queries regarding the animation.

My problem is :
    Then animation stuff and the JInternalFrame  are overlapped and hence i am not able to show the JInternalFrame completely. I can move the JInternalFrame to some other location, but i don't want it.

My need is :
     Some drawings/pictures in the bottom most layer. Then the animation over it and then the JInternal frame as the top-most layer.

    Any suggestion or solution ???

Herewith i have attached the code also.

To get the JInternalFrame click on the JWindow and then resize the JInternalFrame. ( I don't know why JInternalFrame's size is so big).

Kind Regards,
Prem.

Code:

package test;

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class LastPanel extends JWindow
{
     private static Dimension _dimension = null;
     
     public LastPanel( Dimension d)
     {
          _dimension = d;
     }
     public void paint (Graphics g)
     {
          g.setColor( Color.black);
          g.fillRect( 0, 0, _dimension.width, _dimension.height);
          g.setColor( Color.blue);
          g.fillRect( 100, 100, _dimension.width-200, _dimension.height-200);
     }
     
     public static void main( String args[])
     {
          Toolkit tk = Toolkit.getDefaultToolkit();
          LastPanel lp = new LastPanel( tk.getScreenSize());
          lp.setBounds( 0, 0, tk.getScreenSize().width, tk.getScreenSize().height);
         
          JLayeredPane layeredPane = lp.getLayeredPane();

          JInternalFrame jif = new JInternalFrame( "Test", true,     true,     true,      true);
                                                                  //resizable, closable, maximizable,iconifiable
        jif.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE);
          jif.getContentPane().add( new JLabel( "Label1"));
          jif.setBounds( 10, 15, 100, 100);
          jif.pack();
          jif.setVisible( true);
          jif.moveToFront();

          AnimationPanel ap = new AnimationPanel();
          ap.setBounds( 0, 0, tk.getScreenSize().width, tk.getScreenSize().height);
          layeredPane.add( ap, layeredPane.lowestLayer()+1);
     
          lp.getContentPane().add( jif);
         
          lp.setVisible( true);
     }
     
     public static class AnimationPanel extends JPanel
     {
          private java.util.Timer _timer = null;
          private int _blink = 0;
         
          public AnimationPanel()
          {
               AnimationThread at = new AnimationThread();
               _timer = new java.util.Timer();
               _timer.scheduleAtFixedRate( at, 0, 500);    
               System.out.println( " Thread created ... ");
          }
         
          public void paintComponent( Graphics g)
          {
               if ( _blink == 1)
               {
                    g.setColor( Color.white);
                    _blink = 0;
               }
               else
               {
                    g.setColor( Color.black);
                    _blink = 1;
               }
               Toolkit tk = Toolkit.getDefaultToolkit();    
               g.fillRect( tk.getScreenSize().width/2-100, tk.getScreenSize().height/2-100, 200, 200);
          }
         
          private class AnimationThread extends TimerTask
          {
         
               public void run()
               {
                    Toolkit tk = Toolkit.getDefaultToolkit();
                    paintImmediately( tk.getScreenSize().width/2-100, tk.getScreenSize().height/2-100, 200, 200);
               }
               
          }
     }
     
}
0
Comment
Question by:PremkumarAC
2 Comments
 
LVL 1

Accepted Solution

by:
ruifilipevale earned 300 total points
ID: 6274039
Hello!

If you want I can email to you a nice example of two images overlapping each other (or something like that). It uses the JLayeredPane class. Instead of images you can place what object you want.

My email is rui.vale@ent.efacec.pt

Feel free to contact me!


Hope it helps!


   RFV
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9017734
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to ruifilipevale]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now