Window Menu - Sample Applications
Samples Index Window Menu is added to the Sample
Displays a Message box from the Client's Handler
Sample 5:-
/*
* @(#)AddClientListenerExample.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 add your own Listener to the
application.
*/
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 AddClientListener extends JFrame implements ActionListener
{
//..container
Container desktop;
//..JMenuBar
JMenuBar menuBar;
//..WindowMenu
WindowMenu windowMenu;
public AddClientListener()
{
super("Add Client Listener Example ");
//..create container
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);
//..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);
}
//..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);
}
public void actionPerformed(ActionEvent evt)
{
//..client Listener
JOptionPane.showMessageDialog(this,"Client Listener called : "+evt.getActionCommand());
}
}
public class AddClientListenerExample
{
public static void main(String args[])
{
AddClientListener addClientListener = new AddClientListener();
addClientListener.show();
addClientListener.setSize(400,300);
addClientListener.validate();
}
}


