Jump to content

GUI Issues


Molly

Recommended Posts

Hey guys, I am very new to Java and learning as I go. So far I wrote an Edgeville man killer script to learn a bit, I am now trying to implement a gui and have made one using WindowBuilder in Eclipse but cannot get it to run when my script is started, the script itself and the gui are 2 different classes. The script is probably very sloppy and I likely am trying to run the gui entirely wrong, the knowledge I have of Java is very small. Any help is greatly appreciated!

 

This is the script itself:

 

package Main;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.GroundItem;
import org.osbot.script.rs2.model.Player;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.skill.Skill;
import GUI.EdgeMenGUI;
 
 
 
 
@ScriptManifest(author = "Molly", info = "Edgeville Men version 3", name = "EdgeManKiller", version = 1)
public class EdgeMen extends Script {
final int[] MAN_ID = {313, 314, 315};
int HERB_ID = (207);
boolean HASFOOD;
public static boolean RUN = false;
public static int FOODID;
public static int HPEAT;
Position Room = new Position (3098, 3510, 0);
Position One = new Position (3098, 3503, 0);
Position Bank = new Position (3096, 3494, 0);
Position Two = new Position (3101, 3509, 0);
 
 
 
 
public void onStart() {
 
log("Slay all the men!");
 
}
 
public int onLoop() throws InterruptedException {
 
GroundItem Herb = closestGroundItem(207);
RS2Object Ladder = closestObject(16679);
RS2Object Door = closestObject(11948);
int Hitpoints = client.getSkills().getCurrentLevel(Skill.HITPOINTS);
if (RUN == false) {
new EdgeMenGUI();
}
 
if (Ladder != null) {
LadderHandler();
}
if (Door != null) {
DoorHandler();
}
 
if (Hitpoints < HPEAT) {
EatOrBank();
}
if (Herb != null) {
Loot();
else {
 
Kill();
 
}
return (80);}
 
 
 
private int Loot() throws InterruptedException {
GroundItem Herb = closestGroundItem(207);
Herb.interact("Take");
if (client.getInventory().isFull()) {
Bank();
}
return 500;
}
 
private void Bank() throws InterruptedException {
if (client.getInventory().isFull()) {
walkExact(Room);
sleep(1500);
walkExact(One);
sleep(1500);
walkExact(Bank);
sleep(3000);
RS2Object Bank = closestObject(13446);
Bank.interact("Bank");
sleep(1500);
while (!client.getBank().isOpen())
sleep(200);
client.getBank().depositAll();
sleep(750);
if (client.getBank().contains(FOODID)) {
client.getBank().withdraw5(FOODID);
}
 
sleep(250);
client.getBank().close();
while (client.getBank().isOpen())
sleep(200);
walkExact(One);
sleep(1500);
walkExact(Two);
sleep(1500);
}
}
 
private void Kill() throws InterruptedException {
Player player = client.getMyPlayer();
NPC man = closestNPC(MAN_ID);
if (man != null)
if (!player.isUnderAttack())  
if (!man.isUnderAttack())
man.interact("Attack");
sleep(1000);
}
 
private void LadderHandler() throws InterruptedException {
RS2Object Ladder = closestObject(16679);
Ladder.interact("Climb-down");
sleep(2000);
}
 
private void DoorHandler() throws InterruptedException {
RS2Object Door = closestObject(11948);
Door.interact("Open");
sleep(3000);
}
private void EatOrBank() throws InterruptedException {
if (FOODID != 0) {
if (client.getInventory().contains(FOODID)) {
client.getInventory().interactWithId(FOODID, "Eat");
}
else { 
WalkToBank();
}
}
else {
sleep(500);
}
}
private void WalkToBank() throws InterruptedException {
walkExact(Room);
sleep(1500);
walkExact(One);
sleep(1500);
walkExact(Bank);
sleep(3000);
RS2Object Bank = closestObject(13446);
Bank.interact("Bank");
sleep(1500);
while (!client.getBank().isOpen())
sleep(200);
client.getBank().depositAll();
sleep(750);
if (client.getBank().contains(FOODID)) {
client.getBank().withdraw5(FOODID);
}
else {
 
stop();
}
sleep(250);
client.getBank().close();
while (client.getBank().isOpen())
sleep(200);
walkExact(One);
sleep(1500);
walkExact(Two);
sleep(1500);
 
 
 
}
}
 
 
Here is the GUI class:
 
package GUI;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Main.EdgeMen;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
 
public class EdgeMenGUI {
public String FOOD;
public String HP;
public int FOOD_ID;
public int HP_EAT;
private JFrame frame;
private JTextField txtFood;
private JTextField txtEat;
 
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
EdgeMenGUI window = new EdgeMenGUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
 
/**
* Create the application.
*/
public EdgeMenGUI() {
initialize();
}
 
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
 
JLabel lblFoodId = new JLabel("Food ID:");
lblFoodId.setBounds(100, 96, 46, 14);
frame.getContentPane().add(lblFoodId);
 
JLabel lblNewLabel = new JLabel("Eat At:");
lblNewLabel.setBounds(100, 133, 46, 14);
frame.getContentPane().add(lblNewLabel);
 
JButton btnNewButton = new JButton("Start");
btnNewButton.setBounds(153, 175, 89, 23);
frame.getContentPane().add(btnNewButton);
 
txtFood = new JTextField();
txtFood.setEnabled(false);
txtFood.setBounds(156, 93, 86, 20);
frame.getContentPane().add(txtFood);
txtFood.setColumns(10);
 
txtEat = new JTextField();
txtEat.setEnabled(false);
txtEat.setBounds(156, 130, 86, 20);
frame.getContentPane().add(txtEat);
txtEat.setColumns(10);
 
final JCheckBox chckbxEat = new JCheckBox("Eat");
chckbxEat.setBounds(127, 63, 97, 23);
frame.getContentPane().add(chckbxEat);
 
txtFood = new JTextField();
txtFood.setBounds(156, 93, 86, 20);
frame.getContentPane().add(txtFood);
txtFood.setColumns(10);
 
txtEat = new JTextField();
txtEat.setBounds(156, 130, 86, 20);
frame.getContentPane().add(txtEat);
txtEat.setColumns(10);
 
 
 
 
chckbxEat.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0) {
if (chckbxEat.isSelected());
txtFood.isEnabled();
txtEat.isEnabled();
}
});
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (chckbxEat.isSelected()) {
FOOD = txtFood.getText(); 
HP = txtEat.getText();
try{
 FOOD_ID = Integer.parseInt(FOOD);
 HP_EAT = Integer.parseInt(HP);
} catch (NumberFormatException e) {
 
}}
 
 
else {
FOOD_ID = (0);
HP_EAT = (0);
 
}
EdgeMen.FOODID = FOOD_ID;
EdgeMen.HPEAT = HP_EAT;
EdgeMen.RUN = true;
frame.dispose();
}});
 
}}
 
 
Edited by Molly
Link to comment
Share on other sites

 

Hey guys, I am very new to Java and learning as I go. So far I wrote an Edgeville man killer script to learn a bit, I am now trying to implement a gui and have made one using WindowBuilder in Eclipse but cannot get it to run when my script is started, the script itself and the gui are 2 different classes. The script is probably very sloppy and I likely am trying to run the gui entirely wrong, the knowledge I have of Java is very small. Any help is greatly appreciated!

 

This is the script itself:

 

 

package Main;
import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.GroundItem;
import org.osbot.script.rs2.model.Player;
import org.osbot.script.rs2.model.NPC;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.skill.Skill;
import GUI.EdgeMenGUI;




@ScriptManifest(author = "Molly", info = "Edgeville Men version 3", name = "EdgeManKiller", version = 1)
public class EdgeMen extends Script {
final int[] MAN_ID = {313, 314, 315};
int HERB_ID = (207);
boolean HASFOOD;
public static boolean RUN = false;
public static int FOODID;
public static int HPEAT;
Position Room = new Position (3098, 3510, 0);
Position One = new Position (3098, 3503, 0);
Position Bank = new Position (3096, 3494, 0);
Position Two = new Position (3101, 3509, 0);




public void onStart() {

log("Slay all the men!");

}

public int onLoop() throws InterruptedException {

GroundItem Herb = closestGroundItem(207);
RS2Object Ladder = closestObject(16679);
RS2Object Door = closestObject(11948);
int Hitpoints = client.getSkills().getCurrentLevel(Skill.HITPOINTS);
if (RUN == false) {
new EdgeMenGUI();
}

if (Ladder != null) {
LadderHandler();
}
if (Door != null) {
DoorHandler();
}

if (Hitpoints < HPEAT) {
EatOrBank();
}
if (Herb != null) {
Loot();
} 
else {

Kill();

}
return (80);}



private int Loot() throws InterruptedException {
GroundItem Herb = closestGroundItem(207);
Herb.interact("Take");
if (client.getInventory().isFull()) {
Bank();
}
return 500;
}

private void Bank() throws InterruptedException {
if (client.getInventory().isFull()) {
walkExact(Room);
sleep(1500);
walkExact(One);
sleep(1500);
walkExact(Bank);
sleep(3000);
RS2Object Bank = closestObject(13446);
Bank.interact("Bank");
sleep(1500);
while (!client.getBank().isOpen())
sleep(200);
client.getBank().depositAll();
sleep(750);
if (client.getBank().contains(FOODID)) {
client.getBank().withdraw5(FOODID);
}

sleep(250);
client.getBank().close();
while (client.getBank().isOpen())
sleep(200);
walkExact(One);
sleep(1500);
walkExact(Two);
sleep(1500);
}
}

private void Kill() throws InterruptedException {
Player player = client.getMyPlayer();
NPC man = closestNPC(MAN_ID);
if (man != null)
if (!player.isUnderAttack())  
if (!man.isUnderAttack())
man.interact("Attack");
sleep(1000);
}

private void LadderHandler() throws InterruptedException {
RS2Object Ladder = closestObject(16679);
Ladder.interact("Climb-down");
sleep(2000);
}

private void DoorHandler() throws InterruptedException {
RS2Object Door = closestObject(11948);
Door.interact("Open");
sleep(3000);
}
private void EatOrBank() throws InterruptedException {
if (FOODID != 0) {
if (client.getInventory().contains(FOODID)) {
client.getInventory().interactWithId(FOODID, "Eat");
}
else { 
WalkToBank();
}
}
else {
sleep(500);
}
}
private void WalkToBank() throws InterruptedException {
walkExact(Room);
sleep(1500);
walkExact(One);
sleep(1500);
walkExact(Bank);
sleep(3000);
RS2Object Bank = closestObject(13446);
Bank.interact("Bank");
sleep(1500);
while (!client.getBank().isOpen())
sleep(200);
client.getBank().depositAll();
sleep(750);
if (client.getBank().contains(FOODID)) {
client.getBank().withdraw5(FOODID);
}
else {

stop();
}
sleep(250);
client.getBank().close();
while (client.getBank().isOpen())
sleep(200);
walkExact(One);
sleep(1500);
walkExact(Two);
sleep(1500);



}
}


Here is the GUI class:

package GUI;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Main.EdgeMen;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class EdgeMenGUI {
public String FOOD;
public String HP;
public int FOOD_ID;
public int HP_EAT;
private JFrame frame;
private JTextField txtFood;
private JTextField txtEat;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
EdgeMenGUI window = new EdgeMenGUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public EdgeMenGUI() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);

JLabel lblFoodId = new JLabel("Food ID:");
lblFoodId.setBounds(100, 96, 46, 14);
frame.getContentPane().add(lblFoodId);

JLabel lblNewLabel = new JLabel("Eat At:");
lblNewLabel.setBounds(100, 133, 46, 14);
frame.getContentPane().add(lblNewLabel);

JButton btnNewButton = new JButton("Start");
btnNewButton.setBounds(153, 175, 89, 23);
frame.getContentPane().add(btnNewButton);

txtFood = new JTextField();
txtFood.setEnabled(false);
txtFood.setBounds(156, 93, 86, 20);
frame.getContentPane().add(txtFood);
txtFood.setColumns(10);

txtEat = new JTextField();
txtEat.setEnabled(false);
txtEat.setBounds(156, 130, 86, 20);
frame.getContentPane().add(txtEat);
txtEat.setColumns(10);

final JCheckBox chckbxEat = new JCheckBox("Eat");
chckbxEat.setBounds(127, 63, 97, 23);
frame.getContentPane().add(chckbxEat);

txtFood = new JTextField();
txtFood.setBounds(156, 93, 86, 20);
frame.getContentPane().add(txtFood);
txtFood.setColumns(10);

txtEat = new JTextField();
txtEat.setBounds(156, 130, 86, 20);
frame.getContentPane().add(txtEat);
txtEat.setColumns(10);




chckbxEat.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0) {
if (chckbxEat.isSelected());
txtFood.isEnabled();
txtEat.isEnabled();
}
});
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (chckbxEat.isSelected()) {
FOOD = txtFood.getText(); 
HP = txtEat.getText();
try{
 FOOD_ID = Integer.parseInt(FOOD);
 HP_EAT = Integer.parseInt(HP);
} catch (NumberFormatException e) {

}}


else {
FOOD_ID = (0);
HP_EAT = (0);

}
EdgeMen.FOODID = FOOD_ID;
EdgeMen.HPEAT = HP_EAT;
EdgeMen.RUN = true;
frame.dispose();
}});

}}
 

 

umm quite confused.

if nobody else gets in first just wait like 2-3 mins whilst i find an example in my folders

@ScriptManifest(author="Isolate", info="Project FTB! We Will Succeed!", name="DarkCore ", version=0.1D)

public class Skele extends Script {
      GUI_CLASS_NAME g = new GUI_CLASS_NAME();

    @Override
    public void onStart() {
         g.setVisible(true);
         while(g.isVisible){
            //hold the god damn phone
            }

    }

    @Override
    public void onExit() throws InterruptedException {

    }

    @Override
    public int onLoop() throws InterruptedException {
        Inventory i = client.getInventory();
        Player p = client.getMyPlayer();
        Bank b = client.getBank();


        return random(200, 500);
    }

    @Override
    public void onPaint(Graphics a) {

    }

class GUI_CLASS_NAME extends JFrame{
   //function where you want to close gui{
    g.dispose();
}
   //some pretty buttons
   //sexy functions
   //maybe a radial button or two !
}
}
Link to comment
Share on other sites

umm quite confused.

if nobody else gets in first just wait like 2-3 mins whilst i find an example in my folders

 

Thanks man, like I said I literally have 0 knowledge of Java lol. I initially wrote a script that kills men in edge and eats lobs under 20 hp and it ran fairly well. I wanted to learn how to use a GUI to let the user decided the hp it eats at and what food it eats so I put this together hoping it would work and it doesn't.

Link to comment
Share on other sites

Thanks man, like I said I literally have 0 knowledge of Java lol. I initially wrote a script that kills men in edge and eats lobs under 20 hp and it ran fairly well. I wanted to learn how to use a GUI to let the user decided the hp it eats at and what food it eats so I put this together hoping it would work and it doesn't.

edited my main post with the code

  • Like 1
Link to comment
Share on other sites

public void onStart() {
SwingUtilities.InvokeLater(new Runnable() {
@Override
public void run() {
Gui g = new Gui();
g.setVisible(true);
}
});
}

Based on the fact that he said he's new to Java, I doubt hes going to care about what thread his GUI is running on.

 

@OP this would be the correct way to run the GUI though.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...