jua1 Posted April 28, 2014 Share Posted April 28, 2014 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 More sharing options...
Swizzbeat Posted April 28, 2014 Share Posted April 28, 2014 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. Link to comment Share on other sites More sharing options...
jua1 Posted April 29, 2014 Author Share Posted April 29, 2014 yea so your saying create a main class then make the GUI return which script to use then depending on the return execute that script? Link to comment Share on other sites More sharing options...
Isolate Posted April 29, 2014 Share Posted April 29, 2014 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 More sharing options...
jua1 Posted April 29, 2014 Author Share Posted April 29, 2014 what i ended up doing was create a INT member variable in the GUI Class and depending on what script it selects it changes the value, then in the main it checks that integer. Link to comment Share on other sites More sharing options...