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

Window Menu - Sample Applications

Samples Index

Sample 3:-

/*
* @(#)AddSecondConstructorExample.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 use the second constructor
* of the WindowMenu object.
*/

import java.awt.BorderLayout;
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.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JLabel;
import javax.swing.KeyStroke;

import com.makeLogic.utils.WindowMenu;

public class AddSecondConstructorExample extends JFrame {
 //...Fields
JDesktopPane desktop;
JMenuBar menuBar;
  //..KeyStroke Declarations
KeyStroke cascadeKeyStroke;
KeyStroke tileHorizontallyKeyStroke;
KeyStroke tileVerticallyKeyStroke;
KeyStroke closeAllKeyStroke;


//...Constructors
public AddSecondConstructorExample(){

super("MakeLogic – Add Second Constructor Example");

// assign userdefined KeyStrokes
cascadeKeyStroke=KeyStroke.getKeyStroke('C',java.awt.Event.ALT_MASK,false);
tileHorizontallyKeyStroke=KeyStroke.getKeyStroke('H',java.awt.Event.ALT_MASK,false);
tileVerticallyKeyStroke=KeyStroke.getKeyStroke('V',java.awt.Event.ALT_MASK,false);
closeAllKeyStroke=KeyStroke.getKeyStroke('L',java.awt.Event.ALT_MASK,false);

//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();

//...WindowMenu 2nd constructor
//..creates the WindowMenu using its second constructor
WindowMenu windowMenu = new WindowMenu(desktop,cascadeKeyStroke,
tileHorizontallyKeyStroke,tileVerticallyKeyStroke,closeAllKeyStroke);

//..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[])
{

    AddSecondConstructorExample addSecondConstructorExample = new AddSecondConstructorExample();
    addSecondConstructorExample.setSize(400,300);
    addSecondConstructorExample.validate();
    addSecondConstructorExample.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