Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

public class Main {
    static private Font defaultFont = new Font("Arial", Font.PLAIN, 12);

    static public JMenuItem createJMenuItem(JMenu pMenu, String pText, char pMnemonic, KeyStroke pAccelerator,
            ActionListener pActionListener) throws IllegalArgumentException {
        if (pMenu == null)
            throw new IllegalArgumentException("Menu is missing.");
        if (pText == null)
            throw new IllegalArgumentException("Missing text for menu item.");

        final JMenuItem menuItem = new JMenuItem(pText, pMnemonic);

        if (pAccelerator != null)
            menuItem.setAccelerator(pAccelerator);
        if (pActionListener != null)
            menuItem.addActionListener(pActionListener);
        if (defaultFont != null)
            menuItem.setFont(defaultFont);

        pMenu.add(menuItem);

        return menuItem;
    }
}