Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.awt.Component;

import java.awt.event.KeyEvent;

public class Main {
    /**
     * Simulate a key press/release event on the component.
     * 
     * @param key
     *            KeyEvent.VK_...
     */
    public static void simulateKeyPressed(Component component, int key) {
        component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, 1, key, KeyEvent.CHAR_UNDEFINED));
        component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_RELEASED, 0, 2, key, KeyEvent.CHAR_UNDEFINED));
    }
}