本文整理匯總了Java中java.awt.Window.requestFocus方法的典型用法代碼示例。如果您正苦於以下問題:Java Window.requestFocus方法的具體用法?Java Window.requestFocus怎麽用?Java Window.requestFocus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Window
的用法示例。
在下文中一共展示了Window.requestFocus方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.awt.Window; //導入方法依賴的package包/類
public static void main(final String[] args) throws AWTException {
final Window window = new BackgroundIsNotUpdated(null);
window.setSize(300, 300);
window.setLocationRelativeTo(null);
window.setVisible(true);
window.requestFocus();
final ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(200);
robot.waitForIdle(1000);
window.setBackground(Color.GREEN);
robot.waitForIdle(1000);
Point point = window.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
point.y + window.getHeight() / 2);
window.dispose();
if (!color.equals(Color.GREEN)) {
throw new RuntimeException(
"Expected: " + Color.GREEN + " , Actual: " + color);
}
}
示例2: remove
import java.awt.Window; //導入方法依賴的package包/類
private void remove(LayerPanel layerPanel) {
layerPanels.remove(layerPanel);
overlays.remove(layerPanel.layer);
this.remove((Component)layerPanel);
Dimension lmMaxSize = getMaximumSize();
Dimension size = new Dimension(
lmMaxSize.width+20,
lmMaxSize.height+40);
Dimension maxSize = lmFrame.getMaximumSize();
size.height = Math.min(size.height, maxSize.height);
size.width = Math.min(size.width, maxSize.width);
lmFrame.setMinimumSize(size);
lmFrame.setSize(size);
lmFrame.pack();
this.revalidate();
this.repaint();
if ( lmFrame.isVisible() ) {
Window activeWindow = FocusManager.getCurrentManager().getActiveWindow();
lmFrame.toFront();
if (activeWindow != null) activeWindow.requestFocus();
}
}