Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.AbstractButton;
import javax.swing.JButton;

public class Main {
    /**
     * Creates a new button with the given text.
     *
     * @param text DOCUMENT ME!
     * @param parse DOCUMENT ME!
     *
     * @return new button with the given text.
     *
     * @since 1.0b9
     */
    public static JButton createButton(String text, boolean parse) {
        JButton button = new JButton();

        if (parse) {
            setMenuText(button, text, true);
        } else {
            button.setText(text);
        }

        return button;
    }

    /**
     * Creates a new button with the given text.
     *
     * @param text DOCUMENT ME!
     *
     * @return new button with the given text.
     *
     * @since 1.0b9
     */
    public static JButton createButton(String text) {
        return createButton(text, true);
    }

    /**
     * DOCUMENT ME!
     *
     * @param item DOCUMENT ME!
     * @param text DOCUMENT ME!
     * @param useMnemonic DOCUMENT ME!
     */
    public static void setMenuText(AbstractButton item, String text, boolean useMnemonic) {
        int i = text.indexOf('&');

        if (i < 0) {
            item.setText(text);
        } else {
            item.setText(text.substring(0, i) + text.substring(i + 1));

            if (useMnemonic) {
                item.setMnemonic(text.charAt(i + 1));
            }
        }
    }
}