I decided to go ahead and post the entire script. I made a few changes which I believe were what your goal was. Dealing with threads and concurrency can be a tricky topic. I know I still struggle with it sometimes. There are still many things in this script that can be improved, but I believe you are off to a great start!
I'm hoping that after looking at how I used a boolean to assign whether or not the checkbox was checked after pressing start you will be able to proceed with doing so for the rest of the ore checkboxes. There are many ways that this could have been done, but I believe that this was the simplest and definitely the best way to learn!
Edit: if you have any more questions feel free to ask
package OreLooter;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.GroundItem;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JCheckBox;
@ScriptManifest(author = "Brian", info = "Orelooter", name = "Orelooter", version = 0, logo = "")
public class OreLooter extends Script implements ItemListener {
// Should not be static
Object lock = new Object();
public gui gui = new gui();
private long copperoreCollected;
private long prevInvCount;
private long timeBegan;
private long timeRan;
private long hph;
public boolean clayCheckBox = false;
@Override
public void onStart() throws InterruptedException {
gui.run(this);
synchronized(lock) { // must make the lock object wait which in essence pauses this class from executing until it is notified
lock.wait();
}
prevInvCount = getInventory().getAmount(436);
timeBegan = System.currentTimeMillis();
log("Is clay checkbox selected: " + clayCheckBox);
}
private enum State {
COLLECT, FULL, WALK, WAIT
}
private State getState() {
Area MINE = new Area(3232, 3143, 3221, 3149);
if (inventory.isFull())
return State.FULL;
if (!inventory.isFull() && MINE.contains(myPlayer()))
return State.COLLECT;
if (!MINE.contains(myPlayer()) && !inventory.isFull())
return State.WALK;
return State.WAIT;
}
@Override
public int onLoop() throws InterruptedException {
// none of these are needed as they are already in your gui class.
JCheckBox Clay = new JCheckBox("Clay");
JCheckBox Tin = new JCheckBox("Tin");
JCheckBox Copper = new JCheckBox("Copper");
JCheckBox Iron = new JCheckBox("Iron");
JCheckBox Coal =new JCheckBox("Coal");
if (Coal.isSelected())log("coal is selected");
long invCount = getInventory().getAmount(436);
if (invCount > prevInvCount)
setCOPPER_ORECollected(getCOPPER_ORECollected() + (invCount - prevInvCount));
prevInvCount = invCount;
GroundItem Clayo = groundItems.closest("Clay");
GroundItem Tino = groundItems.closest("Tin ore");
GroundItem Coppero = groundItems.closest("Copper ore");
GroundItem Irono = groundItems.closest("Iron ore");
GroundItem Coalo = groundItems.closest("Coal");
switch (getState()) {
case COLLECT:
if (clayCheckBox) {
if (Clayo != null && getMap().canReach(Clayo))
Clayo.interact("take");
}
if (Tino != null && getMap().canReach(Tino) && Tin.isSelected()) {
log("Tin selected");
Tino.interact("take");
}
if (Copper.isSelected()) {
log("Searching for Copper");
if (Coppero != null && getMap().canReach(Coppero))
log("Copper selected");
Coppero.interact("take");
}
if (Irono != null && getMap().canReach(Irono) && Iron.isSelected()) {
log("Iron selected");
Irono.interact("take");
}
if (Coalo != null && getMap().canReach(Coalo) && Coal.isSelected()) {
log("Coal selected");
Coalo.interact("take");
}
sleep(2000);
break;
case FULL:
walking.webWalk(new Position(3209, 3220, 2));
if (bank.isOpen()) {
bank.depositAll();
} else {
objects.closest("Bank booth").interact("Bank");
}
break;
case WALK:
Area MINE = new Area(3232, 3143, 3221, 3149);
walking.webWalk(MINE);
case WAIT:
}
return (random(400, 1500));
}
@Override
public void onExit() {
log("THANKS APAEC FOR ALL THE HELP");
}
@Override
public void onPaint(Graphics2D g) {
hph = (int) (copperoreCollected / ((System.currentTimeMillis() - timeBegan) / 3600000.0D));
timeRan = System.currentTimeMillis() - this.timeBegan;
Graphics2D gr = (Graphics2D) g;
gr.setColor(Color.WHITE);
gr.setFont(new Font("Arial", Font.BOLD, 12));
g.drawString(formatTime(timeRan), 440, 25);
gr.drawString("Time:", 400, 25);
gr.drawString("" + copperoreCollected, 440, 40);
gr.drawString("Ores:", 400, 40);
gr.drawString("Ores/h:", 400, 65);
g.drawString("" + hph, 450, 65);
gr.setColor(Color.YELLOW);
g.drawString("Gold/h", 400, 78);
g.drawString("" + hph * 37, 450, 78);
g.drawString("Gold:", 400, 52);
g.drawString("" + copperoreCollected * 37, 440, 52);
g.setColor(Color.WHITE);
g.drawRect(390, 10, 100, 75);
}
public String formatTime(long ms) {
long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
s %= 60;
m %= 60;
h %= 24;
return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s)
: h > 0 ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s);
}
public long getCOPPER_ORECollected() {
return copperoreCollected;
}
public void setCOPPER_ORECollected(long COPPER_ORECollected) {
copperoreCollected = COPPER_ORECollected;
}
@Override
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
}
}
package OreLooter;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JCheckBox;
public class gui {
/**
* @wbp.parser.entryPoint
*/
public void run(OreLooter main) {
JFrame jFrame = new JFrame("OSBOT GUI Tutorial");
jFrame.setSize(300, 500);
jFrame.setResizable(false);
JPanel settingsPanel = new JPanel();
settingsPanel.setBackground(Color.DARK_GRAY);
settingsPanel.setForeground(Color.DARK_GRAY);
TitledBorder leftBorder = BorderFactory.createTitledBorder("Settings");
leftBorder.setTitleJustification(TitledBorder.LEFT);
settingsPanel.setBorder(leftBorder);
settingsPanel.setLayout(null);
settingsPanel.setBounds(5, 200, 280, 180);
jFrame.getContentPane().add(settingsPanel);
JPanel startPanel = new JPanel();
startPanel.setBackground(Color.DARK_GRAY);
startPanel.setForeground(Color.DARK_GRAY);
startPanel.setLayout(null);
startPanel.setBounds(5, 350, 70, 20);
jFrame.getContentPane().add(startPanel);
JLabel treeSelection = new JLabel("Select an Ore:");
treeSelection.setFont(new Font("Tahoma", Font.BOLD, 14));
treeSelection.setForeground(Color.GRAY);
treeSelection.setBounds(10, 79, 118, 20);
settingsPanel.add(treeSelection);
JCheckBox Clay = new JCheckBox("Clay");
Clay.setForeground(Color.LIGHT_GRAY);
Clay.setBackground(Color.DARK_GRAY);
Clay.setFont(new Font("Georgia", Font.PLAIN, 13));
Clay.setBounds(154, 27, 97, 23);
settingsPanel.add(Clay);
JCheckBox Tin = new JCheckBox("Tin ore");
Tin.setForeground(Color.LIGHT_GRAY);
Tin.setBackground(Color.DARK_GRAY);
Tin.setFont(new Font("Georgia", Font.PLAIN, 13));
Tin.setBounds(154, 53, 97, 23);
settingsPanel.add(Tin);
JCheckBox Copper = new JCheckBox("Copper ore");
Copper.setForeground(Color.LIGHT_GRAY);
Copper.setBackground(Color.DARK_GRAY);
Copper.setFont(new Font("Georgia", Font.PLAIN, 13));
Copper.setBounds(154, 79, 97, 23);
settingsPanel.add(Copper);
JCheckBox Iron = new JCheckBox("Iron");
Iron.setForeground(Color.LIGHT_GRAY);
Iron.setBackground(Color.DARK_GRAY);
Iron.setFont(new Font("Georgia", Font.PLAIN, 13));
Iron.setBounds(154, 105, 97, 23);
settingsPanel.add(Iron);
JCheckBox Coal = new JCheckBox("Coal");
Coal.setFont(new Font("Georgia", Font.PLAIN, 13));
Coal.setForeground(Color.LIGHT_GRAY);
Coal.setBackground(Color.DARK_GRAY);
Coal.setBounds(154, 131, 97, 23);
settingsPanel.add(Coal);
JButton startButton = new JButton("Start");
startButton.addActionListener(e -> {
jFrame.setVisible(false); // everything that is a setting should be called before you unlock the main class
main.clayCheckBox = Clay.isSelected(); // this is where the boolean for the clayCheckBox is set to true if the clay checkbox is checked
synchronized (main.lock) { // this unlocks the main class and lets it run again
main.lock.notify();
}
});
startButton.setBounds(5, 390, 279, 20);
startPanel.add(startButton);
JLabel lblNewLabel = new JLabel("Ore Lo0ter");
lblNewLabel.setFont(new Font("Georgia", Font.BOLD | Font.ITALIC, 30));
lblNewLabel.setForeground(Color.LIGHT_GRAY);
lblNewLabel.setBounds(10, 11, 197, 110);
startPanel.add(lblNewLabel);
JLabel lblWalksToLumby = new JLabel("lumby east mine, picks up ore, and banks!");
lblWalksToLumby.setFont(new Font("Tahoma", Font.BOLD, 12));
lblWalksToLumby.setForeground(Color.GRAY);
lblWalksToLumby.setBounds(5, 92, 279, 101);
startPanel.add(lblWalksToLumby);
jFrame.setVisible(true);
}
}