So I have been busy at some projects lately. One of them having this project
ill put up the full code and the part i have problems with:
package relax; //importeverything import java.awt.AWTException; import java.awt.Robot; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Relax { //declare some variables for later use. private static boolean Setup = false; private static Robot r = null; private static JFrame f; private static JPanel p; private static JButton b1, b2, b3, b4; private static JLabel l1, l2; private static int Clicks; private static boolean Stop = false; //makes a robot private static void MakeRobot() { try { r = new Robot(); } catch (AWTException e) { //if it fails this will happen e.printStackTrace(); } } public static void main(String[] args) { //initialize everything MakeRobot(); MakeFrame(); AddActionListeners(); } //adds all the actionlisteners to be added public static void AddActionListeners() { b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if (Setup) { InitializeBot(); } } }); b2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { StartSetup(); } }); b3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { f.dispose(); } }); b4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { Stop = true; } }); } //initialize the bot to click for you public static void InitializeBot() { JOptionPane.showMessageDialog(null, "Enter osu! choose your beatmap and dont start (long intro needed)"); r.delay(10000); r.keyPress(KeyEvent.VK_ENTER); r.delay(10); r.keyRelease(KeyEvent.VK_ENTER); r.delay(4990); r.keyPress(KeyEvent.VK_SPACE); r.delay(10); r.keyRelease(KeyEvent.VK_SPACE); r.delay(3990); int Progress = 0; //start the actuall bot while (Stop == false) { r.keyPress(KeyEvent.VK_Z); } } //makes the frame that we will be using private static void MakeFrame() { f = new JFrame("Osu!relax"); p = new JPanel(); b1 = new JButton("Start"); b2 = new JButton("Setup"); b3 = new JButton("Exit"); b4 = new JButton("Stop"); l1 = new JLabel("Current Map: "); l2 = new JLabel("None"); p.add(l1); p.add(l2); p.add(b1); p.add(b4); p.add(b2); p.add(b3); f.add(p); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); f.setSize(500, 500); } //asks the user some information to start the bot public static void StartSetup() { Setup = true; l2.setText(JOptionPane.showInputDialog(null, "Song+Difficulty")); Clicks = Integer.parseInt(JOptionPane.showInputDialog(null, "How Much Clicks?")); int TimingPoints = 0; for (int[] Timing = new int[Clicks];TimingPoints != Clicks; Clicks--) { //---> this shows 1 more timing point JOptionPanes instead of the CLICKS amount I want.. then it gives an error. <--------- Timing[TimingPoints] = (Integer.parseInt(JOptionPane.showInputDialog(null, "what is timing point "))); TimingPoints++; } } }
And here the part i have problems with:
There is some kind of issue here.//asks the user some information to start the bot public static void StartSetup() { Setup = true; l2.setText(JOptionPane.showInputDialog(null, "Song+Difficulty")); Clicks = Integer.parseInt(JOptionPane.showInputDialog(null, "How Much Clicks?")); int TimingPoints = 0; for (int[] Timing = new int[Clicks];TimingPoints != Clicks; Clicks--) { //---> this shows 1 more timing point JOptionPanes instead of the CLICKS amount I want.. then it gives an error. <--------- Timing[TimingPoints] = (Integer.parseInt(JOptionPane.showInputDialog(null, "what is timing point "))); TimingPoints++; } }
in the gui it will ask you to give points in time (ms) it wants to click for you, although when for example i put in 3 at "How Much Clicks" it asks 4 times and then exits with an error.
Here is the error:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
at relax.Relax.StartSetup(Relax.java:175)
at relax.Relax$2.actionPerformed(Relax.java:78)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
im probably just dumb like usual but i really dont get this problem :/
Hope somebody has the time to help!
Greetings,
Niels