Site Map Mail This To A Friend PrivacyPolicy Subscribe to MakeLogic RSS Feed

Window Menu - Sample Applications

Samples Index


Changes the Accelerator of the Cascade option to ctrl+W

Window Menu ScreehShot


Sample 2:-

/*
* @(#)ChangeAcceleratorExample.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 set the Accelerator to the MenuItems
* of the WindowMenu object.
*/


import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JLabel;
import javax.swing.KeyStroke;

import com.makeLogic.utils.WindowMenu;

public class ChangeAcceleratorExample extends JFrame {

//...Fields
JDesktopPane desktop;
JMenuBar menuBar;
KeyStroke cascadeKeyStroke;
KeyStroke tileHorizontallyKeyStroke;
KeyStroke tileVerticallyKeyStroke;
KeyStroke closeAllKeyStroke;

//...Constructors
public ChangeAcceleratorExample(){

    super("MakeLogic – Add ChangeAccelerator Example");

    //Quit this app when the big window closes.
    addWindowListener(new WindowAdapter() {

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

//Set up the GUI.
desktop = new JDesktopPane(); //the container which will host components(InternalFrames)
desktop.putClientProperty("JDesktopPane.dragMode", "outline");
getContentPane().setLayout(new BorderLayout());
getContentPane().add(desktop,BorderLayout.CENTER);
  //add a few internal frames to the desktop pane
for(int i=0;i<5;i++){
    addFrame("InternalFrame : "+ i);
}

//..sets the destop object to the ContentaPane
setContentPane(desktop);

//.. Creates a JMenuBar which hosts all the readymade Menus
menuBar = new JMenuBar();

//..creates a KeyStroke to casecadeMenuItem
cascadeKeyStroke=KeyStroke.getKeyStroke('W',java.awt.Event.CTRL_MASK,false);

//...WindowMenu
//..Creates the ReadyMade WindowMenu
WindowMenu windowMenu = new WindowMenu(desktop);

//..sets the Accelerator for cascadeMenuItem
windowMenu.setKeyStrokeForCascade(cascadeKeyStroke);

//..adds the windowMenu to the MenuBar
menuBar.add(windowMenu);

//..sets the MenuBar to the Container(desktop)
setJMenuBar(menuBar);

}

//...methods
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);

}

//Add the main method
public static void main(String args[])
{
    ChangeAcceleratorExample changeAcceleratorExample = new ChangeAcceleratorExample();
    changeAcceleratorExample.setSize(400,300);
    changeAcceleratorExample.validate();
    changeAcceleratorExample.show();
}
}


Was this information helpful to you?
Rock The Vote Next Poll Question

RSS Feeds
Subscribe to MakeLogic RSS Feed Add to My Yahoo! Add to Google
NewsLetter