Jump to content

Gui-ish Help


Deceiver

Recommended Posts

wat do


 


Issue:


 


I have this sick GUI for a script right? How do I get it to start/load a class from a different package?


 


 


  1. Select option from a JComboBox
  2. Hit "start"
  3. Start selected item with a matching class name?

I've tried populating the JComboBox values two different ways, but neither prevailed, when trying to start the other class.


 


 


My onLoop method: (I want to assume that the problem is in this hopefully)



@Override
public int onLoop() throws InterruptedException {
try {
Class.forName(getName(), true, null);
// Class.forName((String) questName);
log("trying to start: " + questName);
} catch (Exception e) {
log("failed to start: " + questName);
e.printStackTrace();
}

return 500;
}

Link to comment
Share on other sites

a straight forward way to do it is to have your class called 'Gui' which contains the code for your gui. in that class, you have an actionlistener for your start button which gets the current selected settings and sends them statically to your main class.

 

here's how the actionlistener goes:

		btnStart.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				//code here eg: 
                                Main.food = (String) foodComboBox.getSelectedItem();
				setVisible(false);
			}
		});

and your main class:

//vars:
public static String food;
Gui GUI;


@Override
	public void onStart() {
                GUI = new Gui();
                GUI.setVisible(true);
		log("======================================================================");		        log("script started or whatever");
	}


@Override
    public int onLoop() {
         while(GUI.isVisible())
                sleep(400);
    return 200;
}

then the gui will feed you the values chosen on the gui when the start button is pressed, at the same time as running the script (breaking the while loop) and closing the gui.

 

apa


ps sorry for any typos, wrote most of the code in the reply box so there may be a few errors

  • Like 1
Link to comment
Share on other sites

a straight forward way to do it is to have your class called 'Gui' which contains the code for your gui. in that class, you have an actionlistener for your start button which gets the current selected settings and sends them statically to your main class.

 

here's how the actionlistener goes:

		btnStart.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				//code here eg: 
                                Main.food = (String) foodComboBox.getSelectedItem();
				setVisible(false);
			}
		});

and your main class:

//vars:
public static String food;
Gui GUI;


@Override
	public void onStart() {
                GUI = new Gui();
                GUI.setVisible(true);
		log("======================================================================");		        log("script started or whatever");
	}


@Override
    public int onLoop() {
         while(GUI.isVisible())
                sleep(400);
    return 200;
}

then the gui will feed you the values chosen on the gui when the start button is pressed, at the same time as running the script (breaking the while loop) and closing the gui.

 

apa

ps sorry for any typos, wrote most of the code in the reply box so there may be a few errors

 

I have my GUI in my 'main' file. And, I have already added a ActionListenser:

JButton button = new JButton("Start");
    button.addActionListener(event -> {
        questName = (String) questBox.getSelectedItem().toString();
        log("Selected Quest: " + questName);
        frame.dispose();
        synchronized(Test.class) {
            Test.class.notify();
        }
        
        
    });

So, it successfully logs "Selected Quest", and disposes.

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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