Regarding JLayeredPane demo ?

I need any demo program using JLayeredPane  .It should demostrate all the features of the it including  managing layered frames .

pls forward it u got any to satya369@usa.net

Thanks in advance !
-satya
dillikarsAsked:
Who is Participating?
 
expertmbConnect With a Mentor Commented:
hi ,

 here is the demo of JLayeredPane just compile and run it

//Demonstrates the swing layered panes .
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JInternalFrame;

public class TJLayeredPane extends JFrame implements ActionListener{
      JButton button;
      JInternalFrame             frame1;
      JLayeredPane layeredPane;
      JFrame frame = new JFrame();
      static int framecount = 0;
      static final int xOffset = 25;
      static final int yOffset = 25;
      
      int numFrames = 1;

      Integer[] layerConstants = {JLayeredPane.DEFAULT_LAYER,JLayeredPane.PALETTE_LAYER,JLayeredPane.MODAL_LAYER,JLayeredPane.POPUP_LAYER,JLayeredPane.DRAG_LAYER};
      String[] layerNames = {"Default layer","Palette layer","Modale layer","Popup Layer","Drag Layer"};

      Vector  framesVector = new Vector();

      public TJLayeredPane(){
            super("LayeredPane Demo");

            JPanel panel = new JPanel(new GridLayout(3,3));
            panel.setBorder(BorderFactory.createTitledBorder("Click specified button"));
            
            for(int i = 0; i < layerNames.length+1;i++){
                  if(i<layerNames.length){
                    button = new JButton("Add to"+layerNames[i]);
                    button.setActionCommand(layerNames[i]);      
                  }else{
                    button = new JButton("Clear the Frames");      
                    button.setActionCommand("Clear");      
                  //  button.setForeGround(Color.red);      
                  }
            button.addActionListener(this)      ;
            panel.add(button);
      }
      getContentPane().add(panel,BorderLayout.SOUTH);
      //this.add(panel,BorderLayout.SOUTH);
            
      layeredPane = getLayeredPane();

      addWindowListener(new WindowEventHandler());
      setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      setSize(500,500);
      show();
      }
      
      public static void main(String args[]){

            TJLayeredPane frame =  new TJLayeredPane();
      }

      public void actionPerformed(ActionEvent e){
            JButton tempButton = (JButton)e.getSource();

            if(tempButton.getActionCommand() == layerNames[0])      {
                  addInternalFrame(0);
            }
            if(tempButton.getActionCommand() == layerNames[1])      {
                  addInternalFrame(1);
            }
            if(tempButton.getActionCommand() == layerNames[2])      {
                  addInternalFrame(2);
            }
            if(tempButton.getActionCommand() == layerNames[3])      {
                  addInternalFrame(3);
            }
            if(tempButton.getActionCommand() == layerNames[4])      {
                  addInternalFrame(4);
            }
            
            /*if(tempButton.getActionCommand() == "Clear"){
                  for(Enumeration enum = framesVector.elements();enum.hasMoreElements();){
                        (enum.nextElement()).dispose();
                  }
            framecount = 0;
            }*/
      }      

      public void addInternalFrame(int index){

            JInternalFrame iFrame = new JInternalFrame("In" + layerNames[index],true,true,true,true) ;
            
            framesVector.addElement(iFrame);
            
            iFrame.setLocation(xOffset*(framecount),yOffset*(framecount++));

            iFrame.setSize(200,200);
            iFrame.setDefaultCloseOperation(iFrame.DO_NOTHING_ON_CLOSE);
      
            layeredPane.add(iFrame,layerConstants[index]);

      }

      class WindowEventHandler extends WindowAdapter{

            public void windowClosing(WindowEvent e){
                  System.exit(0);
            }
      }

}


good luck


mb...





0
All Courses

From novice to tech pro — start learning today.