本文整理汇总了Java中java.awt.Robot.getPixelColor方法的典型用法代码示例。如果您正苦于以下问题:Java Robot.getPixelColor方法的具体用法?Java Robot.getPixelColor怎么用?Java Robot.getPixelColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Robot
的用法示例。
在下文中一共展示了Robot.getPixelColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
createUI();
Robot robot = new Robot();
robot.waitForIdle();
Rectangle rect = window.getBounds();
rect.x += rect.width - 10;
rect.y += rect.height - 10;
robot.delay(1000);
Color c = robot.getPixelColor(rect.x, rect.y);
try {
if (!c.equals(Color.RED)) {
throw new RuntimeException("Test Failed");
}
} finally {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
background.dispose();
window.dispose();
}
});
}
}
示例2: main
import java.awt.Robot; //导入方法依赖的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);
sleep();
window.setBackground(Color.GREEN);
sleep();
final Robot robot = new Robot();
robot.setAutoDelay(200);
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);
}
}
示例3: testSplash
import java.awt.Robot; //导入方法依赖的package包/类
static void testSplash(ImageInfo test) throws Exception {
SplashScreen splashScreen = SplashScreen.getSplashScreen();
if (splashScreen == null) {
throw new RuntimeException("Splash screen is not shown!");
}
Graphics2D g = splashScreen.createGraphics();
Rectangle splashBounds = splashScreen.getBounds();
int screenX = (int) splashBounds.getCenterX();
int screenY = (int) splashBounds.getCenterY();
Robot robot = new Robot();
Color splashScreenColor = robot.getPixelColor(screenX, screenY);
float scaleFactor = getScaleFactor();
Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
if (!compare(testColor, splashScreenColor)) {
throw new RuntimeException(
"Image with wrong resolution is used for splash screen!");
}
}
示例4: performTest
import java.awt.Robot; //导入方法依赖的package包/类
@Override
protected boolean performTest() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
splitterLoc = sp2.getLocationOnScreen();
Point leftLoc = sp1.getLocationOnScreen();
leftLoc.translate(sp1.getWidth(), 0);
splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Where is splitter?");
}
// run robot
Robot robot = Util.createRobot();
robot.setAutoDelay(ROBOT_DELAY);
robot.mouseMove(splitterLoc.x, splitterLoc.y);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);
Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);
System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);
if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {
fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
clickAndBlink(robot, splitterLoc);
return clicked;
}
示例5: runTest
import java.awt.Robot; //导入方法依赖的package包/类
private static void runTest(Dialog dialog, Frame frame) {
try {
Robot robot = new Robot();
robot.setAutoDelay(50);
robot.mouseMove(300, 300);
while (!dialog.isVisible()) {
sleep();
}
Rectangle dialogBounds = dialog.getBounds();
Rectangle frameBounds = frame.getBounds();
int y1 = dialogBounds.y + dialogBounds.height;
int y2 = frameBounds.y + frameBounds.height;
int clickX = frameBounds.x + frameBounds.width / 2;
int clickY = y1 + (y2 - y1) / 2;
robot.mouseMove(clickX, clickY);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
sleep();
int colorX = dialogBounds.x + dialogBounds.width / 2;
int colorY = dialogBounds.y + dialogBounds.height / 2;
Color color = robot.getPixelColor(colorX, colorY);
dialog.dispose();
frame.dispose();
if (!DIALOG_COLOR.equals(color)) {
throw new RuntimeException("The frame is on top"
+ " of the modal dialog!");
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例6: performTest
import java.awt.Robot; //导入方法依赖的package包/类
protected boolean performTest() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
lLoc = internalFrame.getContentPane().getLocationOnScreen();
lLoc2 = lLoc.getLocation();
lLoc2.translate(0, internalFrame.getContentPane().getHeight() + 10);
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Where is internal frame?");
}
// run robot
Robot robot = Util.createRobot();
robot.setAutoDelay(ROBOT_DELAY);
clickAndBlink(robot, lLoc);
Color c = robot.getPixelColor(lLoc2.x, lLoc2.y);
robot.mouseMove(lLoc2.x, lLoc2.y);
if (!c.equals(AWT_BACKGROUND_COLOR) &&
currentAwtControl.getClass() != java.awt.Scrollbar.class &&
currentAwtControl.getClass() != java.awt.Choice.class) {
fail("The HW component did not pass pixel color check and is not drawn correctly");
}
return lwClicked;
}
示例7: testSplash
import java.awt.Robot; //导入方法依赖的package包/类
static void testSplash(ImageInfo test) throws Exception {
SplashScreen splashScreen = SplashScreen.getSplashScreen();
if (splashScreen == null) {
throw new RuntimeException("Splash screen is not shown!");
}
Graphics2D g = splashScreen.createGraphics();
Rectangle splashBounds = splashScreen.getBounds();
int screenX = (int) splashBounds.getCenterX();
int screenY = (int) splashBounds.getCenterY();
if (splashBounds.width != IMAGE_WIDTH) {
throw new RuntimeException(
"SplashScreen#getBounds has wrong width");
}
if (splashBounds.height != IMAGE_HEIGHT) {
throw new RuntimeException(
"SplashScreen#getBounds has wrong height");
}
Robot robot = new Robot();
Color splashScreenColor = robot.getPixelColor(screenX, screenY);
float scaleFactor = getScaleFactor();
Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
if (!compare(testColor, splashScreenColor)) {
throw new RuntimeException(
"Image with wrong resolution is used for splash screen!");
}
}
示例8: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(() -> createAndShowGUI());
robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> {
scale = frame.getGraphicsConfiguration().getDefaultTransform()
.getScaleX();
Point location = frame.getLocation();
Dimension size = frame.getSize();
centerX = location.x + size.width / 2;
centerY = location.y + size.height / 2;
});
robot.waitForIdle();
robot.mouseMove(centerX, centerY);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
Thread.sleep(100);
Color color = robot.getPixelColor(centerX, centerY);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
SwingUtilities.invokeAndWait(() -> frame.dispose());
if ((scale == 1 && !similar(color, COLOR_1X))
|| (scale == 2 && !similar(color, COLOR_2X))) {
throw new RuntimeException("Colors are different!");
}
}
示例9: testSplash
import java.awt.Robot; //导入方法依赖的package包/类
static void testSplash(ImageInfo test) throws Exception {
SplashScreen splashScreen = SplashScreen.getSplashScreen();
if (splashScreen == null) {
throw new RuntimeException("Splash screen is not shown!");
}
Graphics2D g = splashScreen.createGraphics();
Rectangle splashBounds = splashScreen.getBounds();
int screenX = (int) splashBounds.getCenterX();
int screenY = (int) splashBounds.getCenterY();
if(splashBounds.width != IMAGE_WIDTH){
throw new RuntimeException(
"SplashScreen#getBounds has wrong width");
}
if(splashBounds.height != IMAGE_HEIGHT){
throw new RuntimeException(
"SplashScreen#getBounds has wrong height");
}
Robot robot = new Robot();
Color splashScreenColor = robot.getPixelColor(screenX, screenY);
float scaleFactor = getScaleFactor();
Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
if (!compare(testColor, splashScreenColor)) {
throw new RuntimeException(
"Image with wrong resolution is used for splash screen!");
}
}
示例10: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final Frame frame = new Frame();
final Component label = new PaintNativeOnUpdate();
frame.setBackground(Color.RED);
frame.add(label);
frame.setSize(300, 300);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
sleep();
label.repaint();// first paint
sleep();
label.repaint();// incremental paint
sleep();
Robot robot = new Robot();
robot.setAutoDelay(50);
Point point = label.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
point.y + label.getHeight() / 2);
if (!color.equals(Color.GREEN)) {
System.err.println("Expected color = " + Color.GREEN);
System.err.println("Actual color = " + color);
throw new RuntimeException();
}
frame.dispose();
}
示例11: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Windows only test
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
// Retrieving top edge of Desktop
GraphicsConfiguration grConf = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
Rectangle scrRect = grConf.getBounds();
Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
scrTop = scrRect.y + scrInsets.top;
color = new Color(0, 255, 0);
SwingUtilities.invokeAndWait(() -> {
createAndShowUI();
});
try {
Robot robot = new Robot();
robot.setAutoDelay(500);
robot.setAutoWaitForIdle(true);
robot.delay(1000);
// Resizing a window to invoke Windows Snap feature
readFrameInfo();
robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Retrieving the color of window expanded area
readFrameInfo();
Insets insets = frame.getInsets();
Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,
frLoc.y + frSize.height - insets.bottom - 1);
frame.dispose();
if (!bgColor.equals(color)) {
throw new RuntimeException("TEST FAILED: got "
+ bgColor + " instead of " + color);
}
System.out.println("TEST PASSED!");
} catch (AWTException ex) {
throw new RuntimeException("TEST FAILED!");
}
}
}
示例12: performTest
import java.awt.Robot; //导入方法依赖的package包/类
protected boolean performTest() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
lLoc = internalFrame.getContentPane().getLocationOnScreen();
lLoc2 = lLoc.getLocation();
lLoc2.translate(0, internalFrame.getHeight());
frameLoc = frame.getLocationOnScreen();
frameLoc.translate(frame.getWidth()/2, 3);
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Where is internal frame?");
}
// run robot
Robot robot = Util.createRobot();
robot.setAutoDelay(ROBOT_DELAY);
// force focus on JFrame (jtreg workaround)
robot.mouseMove(frameLoc.x, frameLoc.y);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
//slow move
robot.mouseMove(lLoc.x + 25, lLoc.y - 5);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(100);
robot.mouseMove(lLoc.x + 45, lLoc.y - 5);
robot.delay(100);
robot.mouseMove(lLoc.x + internalWidth - 75, lLoc.y - 5);
robot.delay(100);
robot.mouseMove(lLoc.x + internalWidth - 55, lLoc.y - 5);
robot.delay(100);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Color c2 = robot.getPixelColor(lLoc.x + internalWidth + 15, lLoc.y - 5);
if (c2.equals(AWT_BACKGROUND_COLOR)) {
error("Foreground frame is not drawn properly");
}
Color c = robot.getPixelColor(lLoc.x + internalWidth - 95, lLoc.y + 5);
robot.mouseMove(lLoc.x + internalWidth - 95, lLoc.y + 5);
System.out.println("color: " + c + " " + AWT_BACKGROUND_COLOR);
if (!c.equals(AWT_BACKGROUND_COLOR) && currentAwtControl.getClass() != java.awt.Scrollbar.class) {
error("Background AWT component is not drawn properly");
}
return true;
}
示例13: performTest
import java.awt.Robot; //导入方法依赖的package包/类
@Override
protected boolean performTest() {
int BORDER_SHIFT = frameBorderCounter();
BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : (BORDER_SHIFT / 2);
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
lLoc = frame.getLocationOnScreen();
size = frame.getSize();
lLoc2 = frame.getContentPane().getLocationOnScreen();
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Where is frame?");
}
Robot robot = Util.createRobot();
robot.setAutoDelay(ROBOT_DELAY/2);
// resize window
robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_MASK);
for (int i = 0; i < 10; i++) {
robot.mouseMove(lLoc.x + size.width / 2 + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT + 20 * i);
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT, lLoc.y + size.height + BORDER_SHIFT);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_MASK);
for (int i = 0; i < 10; i++) {
robot.mouseMove(lLoc.x + size.width + BORDER_SHIFT + 20 * i, lLoc.y + size.height + BORDER_SHIFT);
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
// check if component is visible on the opened space
try {
Thread.sleep(300); //some more wait for Solaris (for some reason)
}catch(Exception ex) {}
lLoc2.translate(75, 75);
Color c = robot.getPixelColor(lLoc2.x, lLoc2.y);
System.out.println("Actual: "+c+", expected: "+AWT_VERIFY_COLOR);
if (!c.equals(AWT_VERIFY_COLOR)) {
fail("HW component is not visible after resizing");
}
return true;
}
示例14: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
JPanel panel = new JPanel();
panel.setBackground(BACKGROUND);
frame.getContentPane().add(panel);
frame.setVisible(true);
});
robot.waitForIdle();
Thread.sleep(200);
Rectangle[] rects = new Rectangle[1];
SwingUtilities.invokeAndWait(() -> {
rects[0] = frame.getBounds();
});
Rectangle bounds = rects[0];
int x = bounds.x + bounds.width / 4;
int y = bounds.y + bounds.height / 4;
Color color = robot.getPixelColor(x, y);
if (!BACKGROUND.equals(color)) {
throw new RuntimeException("Wrong backgound color!");
}
x = bounds.x + 3 * bounds.width / 4;
y = bounds.y + 3 * bounds.height / 4;
color = robot.getPixelColor(x, y);
if (!BACKGROUND.equals(color)) {
throw new RuntimeException("Wrong backgound color!");
}
}
示例15: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsDevice.WindowTranslucency mode = GraphicsDevice.WindowTranslucency.TRANSLUCENT;
boolean translucencyCheck = gd.isWindowTranslucencySupported(mode);
if(!translucencyCheck) {
return;
}
Robot robot = new Robot();
// create a GUI
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
robot.waitForIdle();
Color opaque = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100);
// set Dialog Opacity
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
dialog.setOpacity(OPACITY);
}
});
robot.waitForIdle();
// iconify frame
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setExtendedState(JFrame.ICONIFIED);
}
});
robot.waitForIdle();
// deiconify frame
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.setExtendedState(JFrame.NORMAL);
}
});
robot.waitForIdle();
Color transparent = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100);
if (transparent.equals(opaque)) {
frame.dispose();
throw new RuntimeException("JDialog transparency lost "
+ "upon iconify/deiconify sequence");
}
frame.dispose();
}