Jump to content

GUI Script merging


jua1

Recommended Posts

So as the title suggests I have a menu created with swing and a OSbot script.

-Both classes are under the same package

-I currently have the start button actionhandler create a new script() on pressing it

-Im positive this is the wrong way to do it, anyone have some insight that could guide me onto the right path?

	public GUI(){
		super("Menu");
		setLayout(new FlowLayout());
		setSize(300, 200);
		setResizable(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	
		
		Panel = new JPanel();
		Panel.setBackground(Color.yellow);
		add(Panel);
		Panel.add(Box1);
		Panel.add(Box2);
		Panel.add(Button1);
		HandlerClass Handler = new HandlerClass();
		Button1.addActionListener(Handler);
		
		setVisible(true);
	}

	public static void main(String[] args){
		new GUI();
		
	}
	private class HandlerClass implements ActionListener{
		public void actionPerformed(ActionEvent event){
			if(!Box1.isSelected() && !Box2.isSelected()){
				new CatchBirds(); //new script()
			}
		}
	}
}
Link to comment
Share on other sites

An easy way would just be to create an abstract class with a looping method.

public abstract AbstractScript {

    public abstract void loop() throws InterruptedException;

}

Then have your GUI decide which "script" to run and then in your main classes onLoop execute that "scripts" loop method.

strange question, could you:

 

public int loop(){
if(firstScript){
    scrtipOne();
}else if (secondScript){
   scriptTwo();
}
}



public int scriptOne(){
//thecode
}
public int scriptTwo(){
//thecode
}

(void most likly better used void but this was faster to write)

or would this be a bad way of doing it?

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...