我是编程新手,我在java编写一个简单的机器人来分割PDF文档并将它们保存到文件中。现在我的程序询问有多少单据(PDF文件),然后询问有多少页面。问题是它只询问一次有多少页。我需要它询问每个单据中有多少页。首先,我尝试将JOption语句包装在if语句中,但之后变量超出了范围。所以我为每个问题制作了一个方法,一个用于滑动数量,一个用于页面数量。我显然仍然有相同的结果。你能帮帮我吗?
这是我的代码
//RES. 1366 x 768
import javax.swing.JOptionPane;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class automation
{
Robot robot = new Robot();
public static void main(String [] args) throws AWTException
{
new automation();
}
public automation() throws AWTException
{
int medDelay = 200;
int counter2 = 1;
int slips = slips();
int pages = pages();
robot.delay(medDelay);
while (counter2 <= slips)
{
counter2 = counter2 + 1;
//move to file in bridge and double click opens file
robot.delay(3000);
robot.mouseMove(300, 150);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
//maximize reader window
robot.keyPress(KeyEvent.VK_WINDOWS);
robot.keyPress(KeyEvent.VK_UP);
robot.keyRelease(KeyEvent.VK_UP);
robot.keyRelease(KeyEvent.VK_WINDOWS);
robot.delay(medDelay);
//move to tools hit enter
robot.mouseMove(1190, 100);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
//move to text recognition and click
robot.mouseMove(1190, 275);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
//scroll down to in this file click and press enter
robot.mouseMove(1190, 320);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
//move to book marks and click
robot.delay(60000);
robot.mouseMove(10, 170);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
//move to patient name and triple click
int counter1 = 1;
while(counter1 <= pages){
//JOptionPane.showInputDialog("You are on page " + i + "." );
counter1 = counter1+1;
robot.delay(medDelay);
robot.mouseMove(335, 200);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_C);
robot.keyRelease(KeyEvent.VK_C);
robot.keyRelease(KeyEvent.VK_CONTROL);
//move to create book mark and click
robot.mouseMove(180, 175);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseMove(50, 100);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
//JOptionPane.showMessageDialog(null, "You are on page " + i + "." );
}
robot.delay(medDelay);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(medDelay);
robot.mouseMove(10, 170);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseMove(1190, 275);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseMove(1190, 100);
robot.delay(medDelay);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(medDelay);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_Q);
robot.keyRelease(KeyEvent.VK_Q);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.mouseMove(300, 150);
robot.delay(300);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(300);
robot.mouseMove(50, 315);
robot.delay(500);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
}
private int slips() {
String slips = JOptionPane.showInputDialog("How many slips are there?");
int slip = Integer.parseInt(slips);
return slip;
}
private int pages() {
String pages = JOptionPane.showInputDialog("How many pages are there?");
int page = Integer.parseInt(pages);
return page;
}
}
答案 0 :(得分:0)
如果您的代码可读,您将获得更多帮助。这些天你用变量名称,例如m,l,j和t来获得/保持编程位置....请考虑维护程序员。
那就是说,你可能正在寻找这样的东西:
int slips = slips();
int outterCounter = 1;
while (outterCounter <= slips)
{
int pages = pages();
int innerCounter = 1;
while (innerCounter <= pages)
{
// your logic
innerCounter++;
}
outterCounter++;
}
修改:OP原来是基于1 ...