Saturday 15 August 2015

java - Exit a while loop using KeyListener -


I am trying to create my own oppler and use the key lesson to "click" I can. I think a part of the problem is that the window should have a focus to work for a kernelylist, but I have not found any clue about it.

If I add all the code, how can you solve it, you can see it for yourself.

  public class GUIMain JFrame {protected static GUIMain window = null; Protected Static Box MainFrame = New Box (BoxLayout.Y_AXIS); Secure click clicker = null; Public GUIMain (string title) {super (title); MainBox (); Start running (); This.addKeyListener (clicker); This.toFront (); This.pack (); This.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE); This.setVisible (true); } Public static zero main (string [] args) {window = new GUIMain ("AutoClicker v0.1"); } Protected Zero Box () {this.setLayout (New BoxLayout (this.getContentPane (), BoxLayout.Y_AXIS)); MainFrame.setPreferredSize (new dimension (250, 150)); This.getContentPane () setBackground (Color.WHITE). This.add (mainframe); MainFrame.add (Box.createVerticalGlue ()); } Secure Zero startRunning () {JButton startButton = New JButton ("Start"); MainFrame.add (startButton); MainFrame.add (Box.createVerticalGlue ()); StartButton.addActionListener (new executable () {@ Override Public Zero Action Perfid (Action Avent E) {Clicker = New Click ();}}); }}  

and now the "click" class that implements the kernelListener. While I was in the Loop I & lt; 100 pieces have been found, so that there is always no loop to fix it.

  JComponent implies the public class keyListener {Private Static Boolean runClicks = true; Stable robot robot = null; Public click () {mouseClick (); } Fixed fixed zero mouseclick () {int i = 0; Try {robot = new robot (); } Hold (AWTException e) {e.printStackTrace (); } While (runclicks & amp; i & lt; 100) {click (-1440, 540); I ++; }} Private static zero click (int x, int y) {robot.mouseMove (x, y); Robot.delay (50); Robot.mousePress (MouseEvent.BUTTON1_DOWN_MASK); Robot.mouserelease (MouseEvent.BUTTON1_DOWN_MASK); } @ Override Public Zero Key Pressed (KEY EVE) {if (e.getKeyCode () == KeyEvent.VK_F 9) {runClicks = false; }} @ Override Public Wide Key Related (Key Event E) {} @ Override Public Wide Type (Key Event E) {}}  

Do I think of a new way to solve it Is it necessary or can it be done with some modifications?

I'm not a Java expert in any way, but if you have to give a window focus, then you requestFocus () Can use the call

  public static zero main (string [] args) {JFrame frame = new JFrame (); Frame.add // Whatever frame you want to add to your frame and want to resize the frame .requestFocus (); Frame.pack (); Frame.setVisible (true); }  

No comments:

Post a Comment