0

firstly, thank you for any help in advance.

I'm working on a personal project while in school - I would like to make a Table Top System Manager that my wife and I can use to run our homebrewed systems.

Current Road-Block: Working with multiple Default List Models.

Here's how I'm trying to define them at the moment:

public class GameGuideMain extends javax.swing.JFrame {
    private DefaultListModel<Player> playerList;
    private DefaultListModel<Creature> creatureList;
    private DefaultListModel<NPC> npcList;
    
    public GameGuideMain() {
        //Character Default List Models
        //Player
        playerList = new DefaultListModel<Player>();
        //Creature
        creatureList = new DefaultListModel<Creature>();
        //NPC
        npcList = new DefaultListModel<NPC>();

Each of these values extend from Character - I originally tried to define these separate list models as all value, but continued to get red so I tried it this way.

While this did get rid of the Red - I originally faced - now my issue is how would I convert a value type of Character to Player when Player is already extending Character?

My expected result is that these would each be able to add to their respective characterList(s)

A JFrame that includes a label and 3 panels that hold JLists

Jens
  • 67,715
  • 15
  • 98
  • 113
AJBarkus
  • 1
  • 1
  • If your Character value is already a Player instance, you can just cast it. If not, you will need to write a method or Play constructor that copies the data. (If Player, Creature, and NPC all have the same attributes, you may be better off having a single Character class with no subclasses, and instead adding a property to Character of type `public enum CharacterType { PLAYER, CREATURE, NPC }`.) – VGR Apr 02 '23 at 19:45
  • Oh this makes much more sense, thank you so much for this information VGR! I think I'm going to go the route of redefining the CharacterType variable that I defined to instead be an enum property as you described! Thanks again! – AJBarkus Apr 02 '23 at 20:26

0 Answers0