| View previous topic :: View next topic |
| Author |
Message |
clash of clans hacks Master Cheater
Reputation: 63
Joined: 18 Jul 2007 Posts: 368 Location: Remember when we all used to put funny lines here?
|
Posted: Tue Oct 02, 2012 7:22 pm Post subject: Need help with java code |
|
|
I'm trying to make a bot for a game that heals every time my health falls below a certain point, but I'm having some trouble.
It's with color detection, and uses the letter e to heal.
Every time I try it, it just freezes.
| Code: | package THP;
import javax.swing.JPanel;
public class MainPanel extends JPanel {
private JPanel mainpanel;
private Panel1 panel1;
public MainPanel() {
mainpanel = new JPanel();
panel1 = new Panel1();
this.add(panel1);
}
}
|
| Code: | package THP;
import javax.swing.*;
//import java.awt.Desktop.Action;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Panel1 extends JPanel {
private JTextField xField, yField;
private int[] coordinates;
private JButton start;
public Panel1() {
xField = new JTextField(4);
yField = new JTextField(4);
start = new JButton("run");
this.add(xField);
this.add(yField);
this.add(start);
start.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
coordinates = getCoordinates();
new Run(coordinates[0], coordinates[1]);
System.out.print("t");
}
});
}
public int[] getCoordinates() {
coordinates = new int[2];
coordinates[0] = Integer.parseInt(xField.getText());
coordinates[1] = Integer.parseInt(yField.getText());
return coordinates;
}
}
|
| Code: | package THP;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Color;
public class Run {
private Robot robot;
private int[] color, getcolor, testcolor;
private int x, y;
private Boolean run;
public Run(int x, int y) {
this.x = x;
this.y = y;
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
testcolor = getPixelcolor();
run = true;
while(run = true) {
color = getPixelcolor();
if(color == testcolor) {
}
else {
robot.keyPress(69);
System.out.print("test");
}
}
}
public int[] getPixelcolor() {
Color clr= robot.getPixelColor(x,y);
getcolor = new int[3];
getcolor[0]= clr.getRed();
getcolor[1]= clr.getGreen();
getcolor[2] = clr.getBlue();
return color;
}
}
|
| Code: | package THP;
import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Thp extends JFrame {
public JFrame frame;
public MainPanel mainPanel;
public Thp() {
frame = new JFrame("The health program");
frame.setSize(250, 150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainPanel = new MainPanel();
frame.add(mainPanel);
frame.setVisible(true);
}
public static void main(String[] args) {
new Thp();
}
}
|
Any help?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Oct 03, 2012 1:25 pm Post subject: |
|
|
I don't code in Java but looking at your code, I noticed this in your thread:
while(run = true)
Should be:
while(run == true)
_________________
- Retired. |
|
| Back to top |
|
 |
Jesper Grandmaster Cheater Supreme
Reputation: 9
Joined: 21 Feb 2007 Posts: 1156
|
Posted: Fri Oct 05, 2012 2:37 am Post subject: |
|
|
What Wiccaan said is right, or simply make it
Since it is running in a while loop, it freezes since you're not using a thread or any sleep time, it constantly checks the pixel and therefore freezes the application. Make the Run class implement Runnable and make a thread.
|
|
| Back to top |
|
 |
|