Jump to content

How to make a String[] List..?


BrownBird

Recommended Posts

So what I want to do is I have a GUI made up that and the user can choose to loot 6 different items. So, if they want to loot items 1-4 they choose those items, but how would I generate a list in String format so the getItems.closest(lootItem); can read it.. I currently am using an ArrayList to get a list of items but the method can't read it unsure.png

Link to comment
Share on other sites

String[] arrayLoot = list.toArray(new String[list.size()]);

I have this but it still won't pick up any loot at all..

If you make a jlist fast it with an object type, allow multiple selection, you could get an array of selected indexes or object you're if you casted it

I have made my own GUI (interactable paint) so can I still use this mehthod?

Link to comment
Share on other sites

Then there's another issue besides creating the array. Most likely you haven't configured the GUI correctly to configure the users loot selections.

 

This is what I've got:

 

Var:

ArrayList<String> itemLoot = new ArrayList<String>();

String[] lootItem = new String[itemLoot.size()];

 

Method:

GroundItem loot = groundItems.closest(lootItem);

 

GUI:

 if(law) {

                    g.drawImage(img5, 48, 201, null);

                        String l1 = "Law rune";

                        itemLoot.add(l1);

                    } if(death) {

                        g.drawImage(img5, 48, 221, null);

                        String l2 = "Death rune";

                        itemLoot.add(l2);

                    } if(nature) {

                        g.drawImage(img5, 48, 242, null);

                        String l3 = "Nature rune";

                        itemLoot.add(l3);

                    } if(chaos) {

                        g.drawImage(img5, 48, 262, null);

                        String l4 = "Chaos rune";

                        itemLoot.add(l4);

                    } if(bones){

                        g.drawImage(img5, 48, 281, null);

                        String l5 = "Big bones";

                        itemLoot.add(l5);

                    }

 

Link to comment
Share on other sites

This is what I've got:

 

Var:

ArrayList<String> itemLoot = new ArrayList<String>();

String[] lootItem = new String[itemLoot.size()];

 

Method:

GroundItem loot = groundItems.closest(lootItem);

 

GUI:

 if(law) {

                    g.drawImage(img5, 48, 201, null);

                        String l1 = "Law rune";

                        itemLoot.add(l1);

                    } if(death) {

                        g.drawImage(img5, 48, 221, null);

                        String l2 = "Death rune";

                        itemLoot.add(l2);

                    } if(nature) {

                        g.drawImage(img5, 48, 242, null);

                        String l3 = "Nature rune";

                        itemLoot.add(l3);

                    } if(chaos) {

                        g.drawImage(img5, 48, 262, null);

                        String l4 = "Chaos rune";

                        itemLoot.add(l4);

                    } if(bones){

                        g.drawImage(img5, 48, 281, null);

                        String l5 = "Big bones";

                        itemLoot.add(l5);

                    }

 

alright is there anything wrong with it? seems good

Link to comment
Share on other sites

This is what I've got:

 

Var:

ArrayList<String> itemLoot = new ArrayList<String>();

String[] lootItem = new String[itemLoot.size()];

 

Method:

GroundItem loot = groundItems.closest(lootItem);

 

GUI:

 if(law) {

                    g.drawImage(img5, 48, 201, null);

                        String l1 = "Law rune";

                        itemLoot.add(l1);

                    } if(death) {

                        g.drawImage(img5, 48, 221, null);

                        String l2 = "Death rune";

                        itemLoot.add(l2);

                    } if(nature) {

                        g.drawImage(img5, 48, 242, null);

                        String l3 = "Nature rune";

                        itemLoot.add(l3);

                    } if(chaos) {

                        g.drawImage(img5, 48, 262, null);

                        String l4 = "Chaos rune";

                        itemLoot.add(l4);

                    } if(bones){

                        g.drawImage(img5, 48, 281, null);

                        String l5 = "Big bones";

                        itemLoot.add(l5);

                    }

 

Things not pertaining to your question:

  1. Program to the interface (ArrayList -> List)
  2. Your variable naming is terrible plus they're singular when they're representing a multitude of items
  3. Those if statements are disgusting and impossible to maintain. Create an enum of whatever your checking for (loot, runes, idk), assign the constants their corresponding properties, iterate over all the enum values in a clean for-each loop and execute your handler code

On topic:

Log whether your ground item instance is null, make sure the item name is correct, confirm whatever code your using to interact with the item is being executed, etc. There are lots of factors at play here that you're not telling us about.

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