Solved

Urgent : Overlapping JInternalFrame + JPanel

Posted on 2001-07-10
2
870 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 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