本文整理匯總了Java中java.awt.AWTException類的典型用法代碼示例。如果您正苦於以下問題:Java AWTException類的具體用法?Java AWTException怎麽用?Java AWTException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AWTException類屬於java.awt包,在下文中一共展示了AWTException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import java.awt.AWTException; //導入依賴的package包/類
private static void test(GraphicsConfiguration gc) throws AWTException {
final Window frame = new Frame(gc);
try {
frame.addMouseWheelListener(e -> {
wheelX = e.getXOnScreen();
wheelY = e.getYOnScreen();
done = true;
});
frame.setSize(300, 300);
frame.setVisible(true);
final Robot robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
mouseX = frame.getX() + frame.getWidth() / 2;
mouseY = frame.getY() + frame.getHeight() / 2;
robot.mouseMove(mouseX, mouseY);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseWheel(10);
validate();
} finally {
frame.dispose();
}
}
示例2: startCrushing
import java.awt.AWTException; //導入依賴的package包/類
private void startCrushing() {
message = messageET.getText();
String mspStr= mpsET.getText();
try{
mps= Integer.parseInt(mspStr);
delay= 1000/mps;
}catch(Exception e){
label.setText("Please Enter Message / sec Correctly.");
return;
}
try {
robot = new Robot();
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Shivam shiv = new Shivam();
shiv.start();
} catch (AWTException ex) {
}
}
示例3: setup
import java.awt.AWTException; //導入依賴的package包/類
@Override
public void setup() {
// setup keyhook
try {
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);
GlobalScreen.registerNativeHook();
} catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
HKM = new KeyHook();
HKM.addValidHotkey("Space");
GlobalScreen.addNativeKeyListener(HKM);
System.out.println("[KeyHook setup]");
try {
robot = new Robot();
} catch (AWTException e) {
System.out.println("Robot could not be created...");
}
}
示例4: createBackBuffer
import java.awt.AWTException; //導入依賴的package包/類
/**
* Attempts to create an XDBE-based backbuffer for the given peer. If
* the requested configuration is not natively supported, an AWTException
* is thrown. Otherwise, if the backbuffer creation is successful, a
* handle to the native backbuffer is returned.
*/
public long createBackBuffer(X11ComponentPeer peer,
int numBuffers, BufferCapabilities caps)
throws AWTException
{
if (!X11GraphicsDevice.isDBESupported()) {
throw new AWTException("Page flipping is not supported");
}
if (numBuffers > 2) {
throw new AWTException(
"Only double or single buffering is supported");
}
BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
long window = peer.getContentWindow();
int swapAction = getSwapAction(caps.getFlipContents());
return createBackBuffer(window, swapAction);
}
示例5: initSystemTray
import java.awt.AWTException; //導入依賴的package包/類
private static void initSystemTray() {
// add system tray icon with popup menu
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
PopupMenu menu = new PopupMenu();
MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
exitItem.addActionListener(a -> Game.terminate());
menu.add(exitItem);
trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
trayIcon.setImageAutoSize(true);
try {
tray.add(trayIcon);
} catch (AWTException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}
示例6: keyReleased
import java.awt.AWTException; //導入依賴的package包/類
public void keyReleased(KeyEvent e) {
// Fix (workaround) for issue #186557
if (org.openide.util.Utilities.isWindows()) {
if (Boolean.getBoolean("HintsUI.disable.AltEnter.hack")) { // NOI18N
return;
}
if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ALT) {
e.consume();
altReleased = true;
} else if (altEnterPressed && e.getKeyCode() == KeyEvent.VK_ENTER) {
altEnterPressed = false;
if (altReleased) {
try {
java.awt.Robot r = new java.awt.Robot();
r.keyRelease(KeyEvent.VK_ALT);
} catch (AWTException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
示例7: checkCreateImage
import java.awt.AWTException; //導入依賴的package包/類
private static void checkCreateImage(final Component comp,
final boolean isNull) {
if ((comp.createImage(10, 10) != null) == isNull) {
throw new RuntimeException("Image is wrong");
}
if ((comp.createVolatileImage(10, 10) != null) == isNull) {
throw new RuntimeException("Image is wrong");
}
try {
if ((comp.createVolatileImage(10, 10, null) != null) == isNull) {
throw new RuntimeException("Image is wrong");
}
} catch (final AWTException ignored) {
// this check is not applicable
}
}
示例8: initialize
import java.awt.AWTException; //導入依賴的package包/類
/**
* Starts the TrayIcon, if this is supported. If not, it should start a
* simple JDialog, doing the same as independent Window.
*/
private void initialize() {
switch (this.getTrayIconUsage()) {
case TrayIcon:
try {
// --- System-Tray is supported ---------------------
this.getSystemTray().add(this.getTrayIcon(true));
} catch (AWTException e) {
System.err.println("TrayIcon supported, but could not be added. => Use TrayDialog instead !");
this.getAgentGUITrayDialog(true).setVisible(true);
}
break;
case TrayDialog:
this.getAgentGUITrayDialog(true).setVisible(true);
break;
default:
break;
}
// --- Refresh tray icon ------------------------------------
this.getAgentGUITrayPopUp().refreshView();
}
示例9: main
import java.awt.AWTException; //導入依賴的package包/類
public static void main(final String[] args) throws AWTException {
final bug7097771 frame = new bug7097771();
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
final Button button = new Button();
button.addActionListener(frame);
frame.add(button);
frame.setVisible(true);
sleep();
frame.setEnabled(false);
button.setEnabled(false);
button.setEnabled(true);
sleep();
Util.clickOnComp(button, new Robot());
sleep();
frame.dispose();
if (action) {
throw new RuntimeException("Button is not disabled.");
}
}
示例10: execute
import java.awt.AWTException; //導入依賴的package包/類
@Override
public void execute(@NotNull String pattern) {
try {
Robot r = new Robot();
r.keyPress(157);
r.keyPress(90);
r.keyRelease(90);
r.keyRelease(157);
} catch (AWTException e) {
e.printStackTrace();
}
SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);
}
示例11: checkDoubleClickEvent
import java.awt.AWTException; //導入依賴的package包/類
private void checkDoubleClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
events = eventToCheck;
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
actionsArea.setText("");
}
});
driver = new JavaDriver();
WebElement b = driver.findElement(By.name("click-me"));
WebElement t = driver.findElement(By.name("actions"));
Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
Dimension size = EventQueueWait.call_noexc(button, "getSize");
Robot r = new Robot();
r.setAutoDelay(10);
r.setAutoWaitForIdle(true);
r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(50);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
new EventQueueWait() {
@Override public boolean till() {
return actionsArea.getText().contains("(2");
}
}.wait("Waiting for actionsArea failed?");
String expected = t.getText();
tclear();
Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
new Actions(driver).moveToElement(b).doubleClick().perform();
AssertJUnit.assertEquals(expected, t.getText());
}
示例12: main
import java.awt.AWTException; //導入依賴的package包/類
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
示例13: createBackBuffer
import java.awt.AWTException; //導入依賴的package包/類
/**
* Attempts to create a GLX-based backbuffer for the given peer. If
* the requested configuration is not natively supported, an AWTException
* is thrown. Otherwise, if the backbuffer creation is successful, a
* value of 1 is returned.
*/
@Override
public long createBackBuffer(X11ComponentPeer peer,
int numBuffers, BufferCapabilities caps)
throws AWTException
{
if (numBuffers > 2) {
throw new AWTException(
"Only double or single buffering is supported");
}
BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported");
}
if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) {
throw new AWTException("FlipContents.PRIOR is not supported");
}
// non-zero return value means backbuffer creation was successful
// (checked in X11ComponentPeer.flip(), etc.)
return 1;
}
示例14: TakeScreenshot
import java.awt.AWTException; //導入依賴的package包/類
public static void TakeScreenshot(String filePath, String fileName) {
try {
Robot robot = new Robot();
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, "jpg", new File(filePath + fileName + ".jpg"));
} catch (AWTException | IOException ex) {
System.out.println(ex.getMessage());
}
}
示例15: attach
import java.awt.AWTException; //導入依賴的package包/類
@Attachment(type = "image/png", fileExtension = "png", value = "att")
public byte[] attach() {
try {
BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
return imageInByte;
} catch (AWTException | IOException e) {
return null;
}
}