focushandler.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 64 行
JAVA
64 行
/*
* $Id: FocusHandler.java,v 1.1 2003/11/25 11:51:36 epr Exp $
*/
package org.jnode.awt.peer;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.event.FocusEvent;
/**
* Class that holds the focused component.
*
* @author Ewout Prangsma (epr@users.sourceforge.net)
*/
public class FocusHandler {
private Component focusedComponent;
private final JNodeToolkit toolkit;
/***********************************************************************************************
* Creates a new FocusHandler instance
*
* @param toolkit
*/
public FocusHandler(JNodeToolkit toolkit) {
this.toolkit = toolkit;
}
/***********************************************************************************************
* Gets the focused component.
*
* @return The focused component
*/
public Component getFocusedComponent() {
return focusedComponent;
}
/**
* Sets the new focused component and sends some focus events, if necessary.
*
* @param c
*/
public void setFocusedComponent(Component c) {
if (focusedComponent != null) {
sendFocusEvent(focusedComponent, FocusEvent.FOCUS_LOST);
}
this.focusedComponent = c;
if (focusedComponent != null) {
sendFocusEvent(focusedComponent, FocusEvent.FOCUS_GAINED);
}
}
/**
* Sends a focus event.
*
* @param c
* @param what
*/
private final void sendFocusEvent(Component c, int what) {
final EventQueue queue = toolkit.getSystemEventQueue();
queue.postEvent(new FocusEvent(c, what, false));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?