Window Menu - Sample Applications
Samples Index
New functionality of the Window Menu is disabled and Client Handler is called

Sample 6:-
/*
* @(#)DisableDefaultAndAddClientListenerExample.java
*
* Product Of : MakeLogic
* URL : http://www.makelogic.com
* Author : R.Venkatesh
* Date : 1 July, 2003
* email : venkat@makelogicmldb.com
*
* Please feel free to use this Sample Code in your applications.
*/
/*
* This sample Application Demonstrates how to
* disable default Listener and add your own customized Listener.
*/
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import com.makeLogic.utils.WindowMenu;
class DisableDefaultAndAddClientListener extends JFrame implements
ActionListener
{
//..container
Container desktop;
//..JMenuBar
JMenuBar menuBar;
//..WindowMenu
WindowMenu windowMenu;
public DisableDefaultAndAddClientListener()
{
//..calls the Super class constructor
super("Disable Default And Add ClientListener Example");
//..creates container(DesktopPane)
desktop=new JDesktopPane();
//Set up the GUI.
getContentPane().setLayout(new BorderLayout());
getContentPane().add(desktop,BorderLayout.CENTER);
//..Quit this app when the big window closes.
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
//.. Creates a JMenuBar which hosts all the readymade Menus
menuBar=new JMenuBar();
//add a few internal frames to the desktop pane
for(int i=0;i<5;i++)
{
addFrame("InternalFrame : "+ i);
}
//..creates the ReadyMade WindowMenu object
windowMenu =new WindowMenu(desktop);
//..disables the defaultListener of the CascadeMenuItem
windowMenu.disableDefaultCascadeMenuItemListener();
//..adds Listener methods
windowMenu.addCascadeMenuItemActionListener(this);
windowMenu.addTileHorizontalMenuItemActionListener(this);
windowMenu.addTileVerticalMenuItemActionListener(this);
windowMenu.addCloseAllMenuItemActionListener(this);
//..adds the windowMenu to the MenuBar
menuBar.add(windowMenu);
//..sets the MenuBar to the Container(desktop)
setJMenuBar(menuBar);
}
public void addFrame(String title)
{
//..InternalFrame
JInternalFrame internalFrame = new JInternalFrame(title);
JLabel testLabel = new JLabel();
testLabel.setText(title);
desktop.add("South",testLabel);
//..set the Frame Window Size
internalFrame.setSize(200,150);
//..show the InternalFrame
internalFrame.show();
//..add the InternalFrame to the container(desktop)
desktop.add(internalFrame);
}
public void actionPerformed(ActionEvent evt)
{
//..client Listener
JOptionPane.showMessageDialog(this,"Client Listener called : "+evt.getActionCommand());
}
}
public class DisableDefaultAndAddClientListenerExample
{
public static void main(String args[])
{
DisableDefaultAndAddClientListener disableDefaultAndAddClientListener = new DisableDefaultAndAddClientListener();
disableDefaultAndAddClientListener.show();
disableDefaultAndAddClientListener.setSize(400,300);
disableDefaultAndAddClientListener.validate();
}
}


