Solved

Urgent : Overlapping JInternalFrame + JPanel

Posted on 2001-07-10
2
874 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

729 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