Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need help with java code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
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?

PostPosted: Tue Oct 02, 2012 7:22 pm    Post subject: Need help with java code Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Oct 03, 2012 1:25 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Jesper
Grandmaster Cheater Supreme
Reputation: 9

Joined: 21 Feb 2007
Posts: 1156

PostPosted: Fri Oct 05, 2012 2:37 am    Post subject: Reply with quote

What Wiccaan said is right, or simply make it
Code:
while (run) {
}


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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites