Jump to content

Can anyone figure out the problem with this code?


Lol_marcus

Recommended Posts

Basically, if I add an icon to the JOptionPane, it doesn't recognize my option anymore. If I leave it without an image, it does recognize the option. It's obviously something with the code, but what is it? O_O

What it does is, I let the user select the type of log they want, and then perform an action based on that. Here's a snippet:

 

Code that works

	@Override
	public void onStart() throws InterruptedException {	
		
		String userOptions[] = { "Logs", "Oak logs", "Teak logs", "Mahogany logs" };
		String userChoice = "" + (String) JOptionPane.showInputDialog(null, "Choose a log type", "Log Selection Menu",
				JOptionPane.PLAIN_MESSAGE, null, userOptions, userOptions[1]);
	}

Code that doesn't work

	@Override
	public void onStart() throws InterruptedException {
		
		ImageIcon icon = null;
		try {
			icon = new ImageIcon(new URL(
					"https://vignette.wikia.nocookie.net/2007scape/images/6/65/Demon_butler_chathead.png/revision/latest?cb=20151103211007"));
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String userOptions[] = { "Logs", "Oak logs", "Teak logs", "Mahogany logs" };
		String userChoice = "" + (String) JOptionPane.showInputDialog(null, "Choose a log type", "Log Selection Menu",
				JOptionPane.PLAIN_MESSAGE, icon, userOptions, userOptions[1]);
	}

 

Edited by Lol_marcus
Link to comment
Share on other sites

It's not passing on the option to the rest of the script. I'm getting "userChoice is an invalid variable" if I try to do something like getBank().withdrawAll(userChoice); with the code that doesn't work. If I remove all the code to add my icon it works fine. :???:

 

The code itself works, it's just not passing the users choice for some odd reason.

Edited by Lol_marcus
Link to comment
Share on other sites

On 6/6/2020 at 4:40 AM, Lol_marcus said:

It's not passing on the option to the rest of the script. I'm getting "userChoice is an invalid variable" if I try to do something like getBank().withdrawAll(userChoice); with the code that doesn't work. If I remove all the code to add my icon it works fine. :???:

 

The code itself works, it's just not passing the users choice for some odd reason.

If the code above is the same that you are using and you are trying to access the userChoice variable outside of the onStart() than it will show invalid variable, as you have only created that variable inside of the onStart(). Add the userChoice var to the class and set that value in the onStart(), you will than be able to use that variable.

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