What is meant by accelerator keys? Explain application with proper java code.

 Accelerator Key

Accelerator: is a key combination (Ctrl key + letter or function key) which is, if pressed, will trigger action listener associated with the menu or button. For example: F5, Ctrl + O, Ctrl + F5, etc. The associated menu is not displayed if accelerator shortcut is used. The key combination is displayed next to the menu item.

Set Accelerator key for JMenuItem in Java

The following code shows how to set Accelerator key for JMenuItem.

Example

import java.awt.event.KeyEvent;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.KeyStroke;


public class Main {

  public static void main(final String args[]) {

    JFrame frame = new JFrame("MenuSample Example");

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic

    JMenu fileMenu = new JMenu("File");

    fileMenu.setMnemonic(KeyEvent.VK_F);

    menuBar.add(fileMenu);

    // File->New, N - Mnemonic

    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);

    fileMenu.add(newMenuItem);


    // Edit->Paste, P - Mnemonic, CTRL-V - Accelerator, Disabled

    JMenuItem pasteMenuItem = new JMenuItem("Paste", KeyEvent.VK_P);

    KeyStroke ctrlVKeyStroke = KeyStroke.getKeyStroke("control V");

    pasteMenuItem.setAccelerator(ctrlVKeyStroke);

    fileMenu.add(pasteMenuItem);

    frame.setJMenuBar(menuBar);

    frame.setSize(350, 250);

    frame.setVisible(true);

  }

}

The code above generates the following result.




Comments

Popular posts from this blog

What are different steps used in JDBC? Write down a small program showing all steps.

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Discuss classification or taxonomy of virtualization at different levels.