import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestMDI extends JFrame {
JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame jif = new JInternalFrame(
   "Internal Frame", // title
   true,  // resizble
   true,  // closable
   true,  // maximizable
   true); // iconifiable
JButton bt = new JButton("create");
public TestMDI() {
        super();
        setTitle("HandTalker");
// setBackground(Color.lightGray);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
     System.exit(0);
}
});
pack();
setSize(500, 600);
        show(); getContentPane().setLayout(new BorderLayout());
getContentPane().add("North", bt);
desktopPane.setDesktopManager(new OutlineManager());
jif.setBounds(50, 50,100,100);
desktopPane.add(jif);
getContentPane().add("Center", desktopPane);// jif.setSize(50, 50);
// jif.setFrameIcon(new ImageIcon("print.gif"));// JOptionPane.showInternalMessageDialog(bt,"breaking","head",JOptionPane.INFORMATION_MESSAGE);

}

public static void main(String[] args){
TestMDI t = new TestMDI();
}
}
class OutlineManager extends DefaultDesktopManager { 
private Rectangle start, last;
private boolean first = true; // dragging ... public void beginDraggingFrame(JComponent frame) {
initializeOutline(frame);
}
public void dragFrame(JComponent frame, int x, int y) {
updateOutline(frame, x, y, start.width, start.height);
}
public void endDraggingFrame(JComponent frame) {
endOutline(frame);
} // resizing ... public void beginResizingFrame(JComponent frame, int dir) {
initializeOutline(frame);
}
public void resizeFrame(JComponent frame, 
int x, int y, int w, int h) {
updateOutline(frame, x, y, w, h);
}
public void endResizingFrame(JComponent frame) {
endOutline(frame);
} // outline ... private void initializeOutline(final JComponent frame) {
// the call to setVisible() calls repaint, which
// places a paint event on the event queue.
// therefore, the effect of the setVisible() call is
// not apparent until after this method returns frame.setVisible(false);
start = frame.getBounds();
last = new Rectangle(start);
first = true; // the Runnable below paints the initial outline 
// after the repaint event spawned by setVisible() is
// handled SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateOutline(frame,start.x,start.y,
start.width,start.height);
}
});
}
private void updateOutline(JComponent frame, 
int x, int y, int w, int h) {
Container container = frame.getParent();
Graphics g = container.getGraphics(); try {
g.setXORMode(container.getBackground()); if( ! first) {
g.drawRect(last.x, last.y, 
last.width-1, last.height-1);
}
g.drawRect(x, y, w-1, h-1);
first = false;
}
finally {
g.dispose();
last.setBounds(x,y,w,h);
}
}
private void endOutline(JComponent frame) {
frame.setVisible(true);
setBoundsForFrame(
frame, last.x, last.y, last.width, last.height);
}
}