【发布时间】:2015-04-22 20:36:31
【问题描述】:
我是 Java 新手。
我正在尝试显示当前屏幕的屏幕截图并实时更新。 如果我只显示一次它工作正常 但是对于我的大学项目,我应该在两个相邻的屏幕上显示相同的屏幕截图。
我无法弄清楚如何实现这一点。
我找到了两个代码,并试图将它们一起实现,以便获得所需的结果。 http://www.ivoronline.com/Coding/Languages/JAVA/Tutorials/JAVA%20-%20File%20-%20Image%20-%20Display%20Multiple%20Images.php
Capturing and displaying an image using Java
这就是我现在的代码。
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
public class OrionCode_v02 {
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
//JPanel panel = new JPanel();
JFrame theGUI = new JFrame();
//theGUI.getContentPane().add (panel);
theGUI.setTitle("TestApp");
theGUI.setSize(640, 720);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
theGUI.setVisible(true);
JLabel picLabel = new JLabel();
JLabel picLabel2 = new JLabel();
theGUI.add(picLabel);
theGUI.add(picLabel2);
while (true)
{
BufferedImage screenShot = robot.createScreenCapture(new Rectangle(0,0,320,720)); // x-coord, y-coord, width, height
BufferedImage screenShot1 = robot.createScreenCapture(new Rectangle(320,0,320,720)); // x-coord, y-coord, width, height
picLabel.setIcon(new ImageIcon(screenShot1));
picLabel2.setIcon(new ImageIcon(screenShot));
theGUI.add(picLabel);
theGUI.add(picLabel2);
/*
panel.add (new JLabel (new ImageIcon (screenShot)));
panel.add (new JLabel (new ImageIcon (screenShot1)));
*/
}
}
}
它不显示屏幕截图1。 只显示截图。 如果我交换 picLabel.setIcon 的两个命令,那么它会显示 screenshot1。
我需要同时显示两个屏幕截图。 我该怎么办?
【问题讨论】:
标签: java screenshot awtrobot