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

File Menu - sample applications

Samples Index

File Menu Screenshot

New functionality of the File Menu is disabled and Client Handler is called

File Menu Screenshot

/*
* @(#)DisableDefaultAndAddClientListenerExample.java
*
*Product Of : MakeLogic
* URL : http://www.makelogic.com
* Author : R.Venkatesh
* Date : 18 June, 2003
* email : venkat@makelogicmldb.com
*
* Please feel free to use this Sample Code in your applications.
*/

/*
* This sample Application demonstrates how to
* disableDefaultListener and add your own customized listener.
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import java.awt.BorderLayout;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.makeLogic.utils.FileMenu;

class DisableDefaultAndAddClientListener extends JFrame implements ActionListener
{
JDesktopPane desktop;
JLabel statusLabel;
JMenuBar menuBar;
JPanel status;
static int newIndex=0;

//static int newindex=0;
DisableDefaultAndAddClientListener(String title)
{

//..calls the super class constructor
super(title);

//..MenuBar
menuBar = new JMenuBar();

//..Container
desktop=new JDesktopPane();

//..Panel
status=new JPanel();

status.setLayout(new BorderLayout());

//..JLabel
statusLabel=new JLabel();

//..Set InitialText
statusLabel.setText("Click on New to Call the Clients Event Listener");

//..Adds the Label field to the status bar
status.add("West",statusLabel);

//..Gets the ContentPane of the JFrame and adds the container to the center
getContentPane().add("Center",desktop);

//..Gets the ContentPane of the JFrame and adds the JPanel to the South
getContentPane().add("South",status);

//..calls the First constructor of the FileMenu which assigns
//..default KeyStrokes to the MenuItems

FileMenu fileMenu=new FileMenu(desktop);

//..add the fileMenu object to the JMenuBar
menuBar.add(fileMenu);

//..Disables the Default NewMenuItemListener
fileMenu.disableDefaultNewMenuItemListener();

//..add Client New MenuItem Listener
fileMenu.addNewMenuItemActionListener(this);


//..adds the MenuBar to the frame
setJMenuBar(menuBar);

addWindowListener(fileMenu.getDefaultClosingListener());

}
public void actionPerformed(ActionEvent evt)
{

JOptionPane.showMessageDialog(this,"This is clientEvent : " + evt.getActionCommand());

//..Handles Client Events

if(evt.getActionCommand().equalsIgnoreCase("New"))
{
//..increment the count
newIndex++;
//..set the status text
statusLabel.setText(evt.getActionCommand()+"ClientHandler is called "+newIndex+" times");
}

}


}
public class DisableDefaultAndAddClientListenerExample
{

public static void main(String args[])
{

DisableDefaultAndAddClientListener disableAndAddClientListner=new DisableDefaultAndAddClientListener("Disable Default And Add ClientListener Example");
disableAndAddClientListner.show();
disableAndAddClientListner.setSize(500,500);
disableAndAddClientListner.validate();
}

}
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