Results 1 to 4 of 4
  1. #1
    legendofyams is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Exclamation Help with DND Character Creator project

    Hey all. I'm in my final year of Java and as a significant part of our grade we are required to code and final project. I have chosen to make a character creator for DND that allows the user to allocate points to their character's attributes that draw from a point pool. Additionally, based on the character class selected bonus points are allocated to different attributes. Unfortunately, I keep getting an error when trying to compile. Here's the code:

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JPanel.*;
    import javax.swing.JLabel.*;
    import java.util.*;
    import java.text.*;
    
    public class DNDCharCreator extends JApplet {
    
    //RACE=======================================
      // Create a combobox for selecting a race and the array of strings for races
      private String[] races = {"Dragonborn", "Dwarf", "Eladrin", "Elf",
        "Half-elf", "Halfling", "Human", "Tiefling"};
      private JComboBox charRace = new JComboBox(races);
      
    //CLASS======================================
      // Create a combobox for selecting a class and the array of string for classes
      private String[] classes = {"Cleric", "Fighter", "Paladin", "Ranger",
        "Rogue", "Warlock", "Warlord", "Wizard"};
      private JComboBox charClass = new JComboBox(classes);
      
    //ABILITY SCORE==============================
    
      // Create int array for storing ability scores and point pool
      // order of array elements is bank, STR, CON, DEX, INTEL, WIS, CHA
      int[] attPts = new int[7];
      
      /* Create 6 pairs of buttons for increasing and decreasing an attribute's value, a
      message panel that displays the current value of the attribute, and a message panel
      that displays the remaining number of points that can be spent on attributes */
      JLabel pointBank = new JLabel(attPts[0]);
      // STR buttons and messagepanel
      private JButton STRplus = new JButton("+");
      private JButton STRminus = new JButton("-");
      JLabel strValue = new JLabel(attPts[1]);
      // CON buttons and messagepanel
      private JButton CONplus = new JButton("+");
      private JButton CONminus = new JButton("-");
      JLabel conValue = new JLabel(attPts[2]);
      // DEX buttons and messagepanel
      private JButton DEXplus = new JButton("+");
      private JButton DEXminus = new JButton("-");
      JLabel dexValue = new JLabel(attPts[3]);
      // INTEL buttons and messagepanel
      private JButton INTELplus = new JButton("+");
      private JButton INTELminus = new JButton("-");
      JLabel intelValue = new JLabel(attPts[4]);
      // WIS buttons and messagepanel
      private JButton WISplus = new JButton("+");
      private JButton WISminus = new JButton("-");
      JLabel wisValue = new JLabel(attPts[5]);
      // CHA buttons and messagepanel
      private JButton CHAplus = new JButton("+");
      private JButton CHAminus = new JButton("-");
      JLabel chaValue = new JLabel(attPts[6]);
      // combobox for choosing human's bonus attribute
      private String[] bonusAtt = {"Strength", "Constitution", "Dexterity",
        "Intelligence", "Wisdom", "Charisma"};
      private JComboBox humanAtt = new JComboBox(bonusAtt);
    	 
    
      public DNDCharCreator() {
    	 
    	 // Group attribute labels in panel
        JPanel asPanel = new JPanel();
        asPanel.setLayout(new GridLayout(6, 1));
        asPanel.add(new JLabel("Strength"));
        asPanel.add(new JLabel("Constitution"));
        asPanel.add(new JLabel("Dexterity"));
        asPanel.add(new JLabel("Intelligence"));
    	 asPanel.add(new JLabel("Wisdom"));
    	 asPanel.add(new JLabel("Charisma"));
    
        // Group attribute score message panels in panel
        JPanel mpPanel = new JPanel();
        mpPanel.setLayout(new GridLayout(6, 1));
        mpPanel.add(strValue);
        mpPanel.add(conValue);
        mpPanel.add(dexValue);
        mpPanel.add(intelValue);
    	 mpPanel.add(wisValue);
    	 mpPanel.add(chaValue);
    	 
    	 // Group attribute + and - buttons in panel
    	 JPanel abPanel = new JPanel();
        abPanel.setLayout(new GridLayout(6, 2));
        abPanel.add(STRplus);
        abPanel.add(STRminus);
        abPanel.add(CONplus);
        abPanel.add(CONminus);
    	 abPanel.add(DEXplus);
    	 abPanel.add(DEXminus);
    	 abPanel.add(INTELplus);
        abPanel.add(INTELminus);
        abPanel.add(WISplus);
        abPanel.add(WISminus);
    	 abPanel.add(CHAplus);
    	 abPanel.add(CHAminus);
    
    	 // Group asPanel, mpPanel, abPanel into one panel
    	 JPanel attributes = new JPanel();
    	 attributes.add(new JLabel("Ability Score"), BorderLayout.NORTH);
        attributes.add(asPanel, BorderLayout.WEST);
        attributes.add(mpPanel, BorderLayout.CENTER);
    	 attributes.add(abPanel, BorderLayout.EAST);
    	 attributes.add(humanAtt, BorderLayout.SOUTH);
    	 
    	 // Outermost panel for containing all other sub panels
    	 JPanel masterPanel = new JPanel();
    	 masterPanel.setLayout(new GridLayout(6, 1));
    	 masterPanel.add(new JLabel("Race Selection"));
    	 masterPanel.add(charRace);
    	 masterPanel.add(new JLabel("Class Selection"));
    	 masterPanel.add(charClass);
    	 masterPanel.add(new JLabel("Ability Score Point Distribution"));
    	 masterPanel.add(attributes);
      	 
    	 // Register and create a listener for attribute + and - buttons
    	 // STRplus listener
        STRplus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = subBank(attPts[0], attPts[1]);
    		  attPts[1] = increaseAtt(attPts[1]);
          }
        });
    	 // STRminus listener
        STRminus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = addBank(attPts[0], attPts[1]);
    		  attPts[1] = decreaseAtt(attPts[1]);
          }
        });
    	 // CONplus listener
        CONplus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = subBank(attPts[0], attPts[2]);
    		  attPts[2] = increaseAtt(attPts[2]);
          }
        });
    	 // CONminus listener
        CONminus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = addBank(attPts[0], attPts[2]);
    		  attPts[2] = decreaseAtt(attPts[2]);
          }
        });
    	 // DEXplus listener
        DEXplus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = subBank(attPts[0], attPts[3]);
    		  attPts[3] = increaseAtt(attPts[3]);
          }
        });
    	 // DEXminus listener
        DEXminus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = addBank(attPts[0], attPts[3]);
    		  attPts[3] = decreaseAtt(attPts[3]);
          }
        });
    	 // INTELplus listener
        INTELplus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = subBank(attPts[0], attPts[4]);
    		  attPts[4] = increaseAtt(attPts[4]);
          }
        });
    	 // INTELminus listener
        INTELminus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = addBank(attPts[0], attPts[4]);
    		  attPts[4] = decreaseAtt(attPts[4]);
          }
        });
    	 // WISplus listener
        WISplus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = subBank(attPts[0], attPts[5]);
    		  attPts[5] = increaseAtt(attPts[5]);
          }
        });
    	 // WISminus listener
        WISminus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = addBank(attPts[0], attPts[5]);
    		  attPts[5] = decreaseAtt(attPts[5]);
          }
        });
    	 // CHAplus listener
        CHAplus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = subBank(attPts[0], attPts[6]);
    		  attPts[6] = increaseAtt(attPts[6]);
          }
        });
    	 // CHAminus listener
        CHAminus.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            attPts[0] = addBank(attPts[0], attPts[6]);
    		  attPts[6] = decreaseAtt(attPts[6]);
          }
        });
    	 
    	 // charRace listener
    	 charRace.addItemListener(new ItemListener() {
    	   // when the race is changed all attributes and bank are reset, then racial bonus points added
    	   public void itemStateChanged(ItemEvent e) {
    		  int attPts[] = {32, 8, 8, 8, 8, 8, 8};
    		  // ifs that set the first attribute modified
    		  if ((charRace.getSelectedIndex()) == 0) {
    		    humanAtt.setVisible(false);
    		    attPts[1] = (attPts[1] + 2);
    		  }
    		  if (((charRace.getSelectedIndex()) == 1) || ((charRace.getSelectedIndex()) == 4)) {
    		    humanAtt.setVisible(false);
    		    attPts[2] = (attPts[2] + 2);
    		  }
    		  if (((charRace.getSelectedIndex()) == 2) || ((charRace.getSelectedIndex()) == 3) ||
    		   ((charRace.getSelectedIndex()) == 5)) {
    		    humanAtt.setVisible(false);
    		    attPts[3] = (attPts[3] + 2);
    		  }
    		  if ((charRace.getSelectedIndex()) == 7) {
    		    humanAtt.setVisible(false);
    		    attPts[4] = (attPts[4] + 2);
    		  }
    		  // if that set the second attribute modified
    		  if ((charRace.getSelectedIndex()) == 2) {
    		    humanAtt.setVisible(false);
    		    attPts[4] = (attPts[4] + 2);
    		  }
    		  if (((charRace.getSelectedIndex()) == 1) || ((charRace.getSelectedIndex()) == 3)) {
    		    humanAtt.setVisible(false);
    		    attPts[5] = (attPts[5] + 2);
    		  }
    		  if (((charRace.getSelectedIndex()) == 0) || ((charRace.getSelectedIndex()) == 4) ||
    		  ((charRace.getSelectedIndex()) == 5) || ((charRace.getSelectedIndex()) == 7)) {
    		    humanAtt.setVisible(false);
    		    attPts[6] = (attPts[6] + 2);
    		  }
    		}
    	 });
      }
      
      // withdraw appropriate number of points from bank based on attribute value
      private int subBank(int bank, int att) {
    
        // nested ifs subtract appropriate number of points from bank based on current attribute value
    	 if (att == 18)
    	   bank = bank - 0;
    	 else {
    	   if (att == 17)
    		  bank = bank - 4;
    		else {
    		  if (att == 16)
    		    bank = bank - 3;
    		  else {
    		    if (att > 12)
    		      bank = bank - 2;
    		    else
    		      bank = bank - 1;
    		  };
    		};
        };
    	 
    	 // Return bank
    	 return bank;
      }
      
      // deposit appropriate number of points in bank based on attribute value
      private int addBank(int bank, int att) {
    
        // nested ifs add appropriate number of points to bank based on current attribute value
    	 if (att == 18)
    	   bank = bank + 4;
    	 else {
    	   if (att == 17)
    		  bank = bank + 3;
    		else {
    		  if (att > 13)
    		    bank = bank + 2;
    		  else {
    		    if (att > 8)
    		      bank = bank - 2;
    		    else
    		      bank = bank - 0;
    		  };
    		};
        };
    	 
    	 // Return bank
    	 return bank;
      }
      
      // increase an attributes value by 1 if it's under max
      private int increaseAtt(int att) {
    
        if (att < 18)
    	   att++;
    		
        return att;
      }
      
      // decrease an attributes value by 1 if it's over min
      private int decreaseAtt(int att) {
    
        if (att > 8)
    	   att = att - 1;
    		
        return att;
      }
    }
    The error I keep getting is:

    DNDCharCreator.java:32: cannot find symbol
    symbol : constructor JLabel(int)
    location: class javax.swing.JLabel
    JLabel pointBank = new JLabel(attPts[0]);

    I get one for each of the JLabels i've created, for a total of 7 errors. They are JLabels after having initially used MessagePanels, which caused the same errors. I have been looking at this code for so long trying various fixes to no avail, I wonder if I'm not overlooking the simplest problem. Any suggestions?

    Thanks,
    Yams

    PS. I'm aware that my coding is not the neatest nor the most efficient, I'm just going for function, as long as it gets the job done i'll be content. :)

  2. #2
    adamrain is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    sry i cant help im a noob...but i gotta say this is frikin awsome!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The error message is telling you exactly what is wrong: you're trying to call a JLabel constructor by passing an int into it, and there is no such constructor. Solution: don't do this. Read the JLabel API to see what constructors are available and only use those.

  4. #4
    legendofyams is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    I ended up taking your advice and doing just that. thnxmuch. The code was wearing thin on my brain so I was starting to get sloppy. I ended up finishing the program a few days ago (after getting it to work, and rewriting the GUI layout several times so It would look better; I'm terrible with GUI arrangement).

    @ adamrain: Thanks for the kind words man. You may be a noob now but keep challenging yourself writing progressively harder programs and setting small goals and you'll be capable of writing stuff just as complex.
    Last edited by legendofyams; 12-08-2009 at 04:29 PM.

Similar Threads

  1. change value in the in the creator class
    By livnihai in forum New To Java
    Replies: 8
    Last Post: 10-07-2009, 06:14 AM
  2. Read from a certain character to a certain character
    By blackstormattack in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 11:36 AM
  3. Gui Swing Creator
    By 2o2 in forum New To Java
    Replies: 4
    Last Post: 10-01-2008, 11:38 PM
  4. Java Studio Creator - Bd Alterar
    By wagnerbarbos in forum JCreator
    Replies: 0
    Last Post: 06-09-2008, 05:19 PM
  5. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 08:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •