Java Code Examples for javax.swing.JFrame#dispatchEvent()

The following examples show how to use javax.swing.JFrame#dispatchEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandDispatcher.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectDataCommand() {
     JFrame jf = MainWindowManager.mainWindowManager().getMainWindow(1, TimeUnit.MILLISECONDS);

     int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
     KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F, KeyEvent.CHAR_UNDEFINED);
     KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'F' );
     KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F,  KeyEvent.CHAR_UNDEFINED );
     jf.dispatchEvent(pressed);
     jf.dispatchEvent(typed);
     jf.dispatchEvent(released);
   
     mChannel.writeAck("");
}
 
Example 2
Source File: CommandDispatcher.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectAccountCommand() {
    JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();

    int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
    KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED);
    KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'R' );
    KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R,  KeyEvent.CHAR_UNDEFINED );
    jf.dispatchEvent(pressed);
    jf.dispatchEvent(typed);
    jf.dispatchEvent(released);

    mChannel.writeAck("");
}
 
Example 3
Source File: TestGithubIssues.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
@Test( expected = Test.None.class /* no exception expected */ )
public void TestIssue82() throws InterruptedException
{
    // The exception that might be thrown by the date picker control
    // will be thrown in an AWT-EventQueue thread. To be able to detect
    // these exceptions we register an UncaughtExceptionHandler that
    // writes all occurring exceptions into exInfo.
    // As a result we always have access to the latest thrown exception
    // from any running thread
    final ExceptionInfo exInfo = new ExceptionInfo();
    try {
        RegisterUncaughtExceptionHandlerToAllThreads(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException( Thread t, Throwable e ) {
                exInfo.set(t.getName(), e);
            }
        });
        JFrame testWin = new JFrame();
        testWin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        testWin.add(date_picker);
        testWin.pack();
        testWin.setVisible(true);
        Thread.sleep(10);
        assertFalse("DatePicker must not have an open popup.", date_picker.isPopupOpen());
        Thread.sleep(10);
        date_picker.openPopup();
        Thread.sleep(10);
        assertTrue("DatePicker must have an open popup.", date_picker.isPopupOpen());
        testWin.dispatchEvent(new WindowEvent(testWin, WindowEvent.WINDOW_CLOSING));
        Thread.sleep(50);
        assertFalse("Exception in antother Thread triggered:\n"
                +"ThreadName: "+exInfo.getThreadName()+"\n"
                +"Exception: "+exInfo.getExceptionMessage()
                +"\nStacktrace:\n"+exInfo.getStackTrace()
                , exInfo.wasSet());
        } finally {
            RegisterUncaughtExceptionHandlerToAllThreads(null);
    }
}
 
Example 4
Source File: SwingUtils.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JFrame dialog) {
	Action dispatchClosing = new AbstractAction() {
		public void actionPerformed(ActionEvent event) {
			dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
		}
	};
	JRootPane root = dialog.getRootPane();
	installCloseAction(dispatchClosing, root);
}
 
Example 5
Source File: CommandDispatcher.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectDataCommand() {
     JFrame jf = MainWindowManager.mainWindowManager().getMainWindow(1, TimeUnit.MILLISECONDS);

     int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
     KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F, KeyEvent.CHAR_UNDEFINED);
     KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'F' );
     KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F,  KeyEvent.CHAR_UNDEFINED );
     jf.dispatchEvent(pressed);
     jf.dispatchEvent(typed);
     jf.dispatchEvent(released);
   
     mChannel.writeAck("");
}
 
Example 6
Source File: CommandDispatcher.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectAccountCommand() {
    JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();

    int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
    KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED);
    KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'R' );
    KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R,  KeyEvent.CHAR_UNDEFINED );
    jf.dispatchEvent(pressed);
    jf.dispatchEvent(typed);
    jf.dispatchEvent(released);

    mChannel.writeAck("");
}
 
Example 7
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
protected void exitActionPerformed(ActionEvent evt) {
    JFrame frame = (JFrame) mainFrame;
    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
}