Results 1 to 5 of 5
  1. #1
    JHumphr is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Post Okay forum, help me out with this GUI please?

    I am making an auto-typing script. I am having trouble and I don't know where. Thanks in advanced!
    PS: I have a class that creates an Action variable and calls the setdefaultcloseoperation, setsize, and setvisible
    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;

    public class Action extends JFrame{
    private JTextField text;
    private JTextField time;
    private JButton b;
    private int itime;
    private String botText;
    private Robot robot;

    public Action(){
    super("AutoTyper");
    setLayout(new FlowLayout());
    text = new JTextField("Text.",10);
    add(text);
    time = new JTextField("Time (seconds):",10);
    add(time);
    b = new JButton("Start.");
    add(b);
    HandlerClass handler = new HandlerClass();
    text.addActionListener(handler);
    time.addActionListener(handler);
    b.addActionListener(handler);
    }

    public class HandlerClass implements ActionListener{
    public void actionPerformed(ActionEvent event){
    try {
    run();
    } catch (Exception e) {}
    }
    }

    public void run() throws AWTException{
    try{
    itime = Integer.parseInt(time.getText());
    }catch(Exception ex){}
    botText = text.getText();
    int length = botText.length();
    char[] charText = botText.toCharArray();
    setVisible(false);
    while(itime > 0){
    for(int z = 0;z<length;z++){
    sendChar(charText[z]);
    }
    robot.keyPress(KeyEvent.VK_ENTER);
    try{
    Thread.sleep(1000);
    }catch(Exception ex){}
    itime--;
    }
    setVisible(true);
    }

    public void sendChar(char a) throws AWTException{
    a = Character.toLowerCase(a);
    switch(a){
    case ' ':
    robot.keyPress(KeyEvent.VK_SPACE);
    break;
    case 'a':
    robot.keyPress(KeyEvent.VK_A);
    break;
    case 'b':
    robot.keyPress(KeyEvent.VK_B);
    break;
    case 'c':
    robot.keyPress(KeyEvent.VK_C);
    break;
    case 'd':
    robot.keyPress(KeyEvent.VK_D);
    break;
    case 'e':
    robot.keyPress(KeyEvent.VK_E);
    break;
    case 'f':
    robot.keyPress(KeyEvent.VK_F);
    break;
    case 'g':
    robot.keyPress(KeyEvent.VK_G);
    break;
    case 'h':
    robot.keyPress(KeyEvent.VK_H);
    break;
    case 'i':
    robot.keyPress(KeyEvent.VK_I);
    break;
    case 'j':
    robot.keyPress(KeyEvent.VK_J);
    break;
    case 'k':
    robot.keyPress(KeyEvent.VK_K);
    break;
    case 'l':
    robot.keyPress(KeyEvent.VK_L);
    break;
    case 'm':
    robot.keyPress(KeyEvent.VK_M);
    break;
    case 'n':
    robot.keyPress(KeyEvent.VK_N);
    break;
    case 'o':
    robot.keyPress(KeyEvent.VK_O);
    break;
    case 'p':
    robot.keyPress(KeyEvent.VK_P);
    break;
    case 'q':
    robot.keyPress(KeyEvent.VK_Q);
    break;
    case 'r':
    robot.keyPress(KeyEvent.VK_R);
    break;
    case 's':
    robot.keyPress(KeyEvent.VK_S);
    break;
    case 't':
    robot.keyPress(KeyEvent.VK_T);
    break;
    case 'u':
    robot.keyPress(KeyEvent.VK_U);
    break;
    case 'v':
    robot.keyPress(KeyEvent.VK_V);
    break;
    case 'w':
    robot.keyPress(KeyEvent.VK_W);
    break;
    case 'x':
    robot.keyPress(KeyEvent.VK_X);
    break;
    case 'y':
    robot.keyPress(KeyEvent.VK_Y);
    break;
    case 'z':
    robot.keyPress(KeyEvent.VK_Z);
    break;
    case '1':
    robot.keyPress(KeyEvent.VK_1);
    break;
    case '2':
    robot.keyPress(KeyEvent.VK_2);
    break;
    case '3':
    robot.keyPress(KeyEvent.VK_3);
    break;
    case '4':
    robot.keyPress(KeyEvent.VK_4);
    break;
    case '5':
    robot.keyPress(KeyEvent.VK_5);
    break;
    case '6':
    robot.keyPress(KeyEvent.VK_6);
    break;
    case '7':
    robot.keyPress(KeyEvent.VK_7);
    break;
    case '8':
    robot.keyPress(KeyEvent.VK_8);
    break;
    case '9':
    robot.keyPress(KeyEvent.VK_9);
    break;
    case '0':
    robot.keyPress(KeyEvent.VK_0);
    break;
    case '*':
    robot.keyPress(KeyEvent.VK_ASTERISK);
    break;
    case '&':
    robot.keyPress(KeyEvent.VK_AMPERSAND);
    break;
    case '@':
    robot.keyPress(KeyEvent.VK_AT);
    break;
    /*case '\':
    robot.keyPress(KeyEvent.VK_BACK_SLASH);
    break;*/
    case '[':
    robot.keyPress(KeyEvent.VK_BRACELEFT);
    break;
    case ']':
    robot.keyPress(KeyEvent.VK_BRACERIGHT);
    break;
    case '^':
    robot.keyPress(KeyEvent.VK_CIRCUMFLEX);
    break;
    case '{':
    robot.keyPress(KeyEvent.VK_OPEN_BRACKET);
    break;
    case '}':
    robot.keyPress(KeyEvent.VK_CLOSE_BRACKET);
    break;
    case ':':
    robot.keyPress(KeyEvent.VK_COLON);
    break;
    case '$':
    robot.keyPress(KeyEvent.VK_DOLLAR);
    break;
    case '!':
    robot.keyPress(KeyEvent.VK_EXCLAMATION_MARK);
    break;
    case '(':
    robot.keyPress(KeyEvent.VK_LEFT_PARENTHESIS);
    break;
    case ')':
    robot.keyPress(KeyEvent.VK_RIGHT_PARENTHESIS);
    break;
    case '+':
    robot.keyPress(KeyEvent.VK_PLUS);
    break;
    case '-':
    robot.keyPress(KeyEvent.VK_MINUS);
    break;
    case '#':
    robot.keyPress(KeyEvent.VK_NUMBER_SIGN);
    break;
    case '.':
    robot.keyPress(KeyEvent.VK_PERIOD);
    break;
    case ';':
    robot.keyPress(KeyEvent.VK_SEMICOLON);
    break;
    case '_':
    robot.keyPress(KeyEvent.VK_UNDERSCORE);
    break;
    }
    }
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    I am having trouble and I don't know where
    Please describe in full detail what the trouble is...does the code compile? Are there exceptions? Does it behave, and if not what do you expect and what do you get? Lastly, please use the code tags to make your code readable

  3. #3
    JHumphr is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Sorry, new to forum'ing. Anyways, my JFrame displays fine, and I can input perfectly, but it won't type what it is supposed to to the screen. Is it because I am back-grounding the JFrame and it won't run unless it is active?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Could you put your code in code tags to preserve its formatting. See: BB Code List - Java Forums

    Comment on the name of your class. There is a Java class named Action. Can you make yours unique?

    Where is the cursor when the Robot class calls keyPress? Where is the letter being typed?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Did you forget that a pressed key needs to be released before the next key is pressed?

    db

Similar Threads

  1. New to this forum
    By thestranger in forum Introductions
    Replies: 6
    Last Post: 07-27-2008, 09:53 AM
  2. hello forum....
    By Vijay Swaminatha in forum Introductions
    Replies: 3
    Last Post: 06-29-2008, 05:58 AM
  3. New sub forum
    By tim in forum Suggestions & Feedback
    Replies: 3
    Last Post: 03-17-2008, 08:12 PM
  4. Welcome to our new forum: Forum Lobby
    By JavaForums in forum Forum Lobby
    Replies: 18
    Last Post: 02-07-2008, 05:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •