Link to home
Start Free TrialLog in
Avatar of PremkumarAC
PremkumarAC

asked on

Urgent : Overlapping JInternalFrame + JPanel

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);
               }
               
          }
     }
     
}
ASKER CERTIFIED SOLUTION
Avatar of ruifilipevale
ruifilipevale

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sudhakar_koundinya
sudhakar_koundinya

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.